How to Test AI-Generated Code (Without Trusting the Model That Wrote It)
To test AI-generated code, review the diff, run the tests and verify behavior against independently defined requirements. AI-generated tests can repeat the same mistaken assumptions as the implementation, so review their expected results as carefully as the code.
Why the model’s own tests are not enough
Ask a model to write a feature and then to write the tests, and you get two outputs built on the same understanding of the problem. If it misread the requirement, the code is wrong and the tests encode the same mistake. Everything is green, and the bug ships.
This is the central problem with vibe coding. The code looks plausible, the tests pass, and nobody has seen the product behave the way a customer will use it. The failure is not that the model is careless. It is that code and tests share one author, so they share blind spots.
Watch for these failure patterns:
- Tests that mirror the implementation. The test derives its expected result from the same logic as the implementation, so both can make the same mistake.
- Happy paths only. The form works with a normal name and a normal email. Nobody tried an apostrophe, an emoji or an empty field.
- Mocks that hide reality. The payment call is stubbed, so the test never learns that the real provider rejects the request.
- Confident but untested edges. Time zones, rounding, pagination, retries, leap days.
What to actually check
You do not need to test everything. You need to test the places where a plausible mistake is expensive.
Business logic
Take the rules your product lives on (pricing, discounts, permissions, status changes, limits) and check them by hand against a calculation you did yourself. Do not compare the app to the model’s explanation of the app. Compare it to the spec, the spreadsheet or the contract.
Edge cases and bad input
Try empty values, very long values, special characters, a negative quantity, zero, a date in the past, a double click on the submit button, and the back button halfway through a flow. Check these cases explicitly rather than assuming the generated implementation handles them.
Permissions and basic security
This is where “vibe coding security” becomes real. Check that one user cannot open another user’s data by changing an ID in the URL. Check that an admin screen is protected on the server, not just hidden in the interface. Look for secrets pasted into the repository, secret API keys exposed to the browser, and endpoints that accept anything. None of this needs a security team to start. It needs someone who is asking “what if I am not the user you expected?”
Real data
Demo data is tidy. Production data is not. Test with long names, accents, duplicated records, old accounts created before a schema change, and a representative messy export, using synthetic or appropriately anonymized data.
Real devices and browsers
A layout that looks right in the browser the developer uses can break on a small phone, an older tablet or a different operating system. Behavior also changes on slow networks and with the keyboard open. If you serve more than one platform, the test has to happen on more than one. Our device lab exists for that reason.
A practical checklist
Use this before you release anything the model wrote:
| Area | Question to answer |
|---|---|
| Requirements | Does it do what the spec says, checked against the spec and not the code? |
| Money and math | Do totals, discounts, taxes and rounding match a hand calculation? |
| Inputs | What happens with empty, huge, odd or malicious values? |
| Permissions | Can a user reach data or actions that belong to someone else? |
| Secrets | Are secrets absent from source control and client bundles, including repository history? |
| Errors | Does a failed request show a useful message, or a blank screen? |
| State | Does it survive a refresh, a back button, two tabs and a lost connection? |
| Data | Does it work with old, large and messy records? |
| Devices | Does it work on the phones, TVs and desktops your users own? |
| Regression | Did the fix for one bug break something that worked yesterday? |
For that last row, see our guide to regression testing.
Where automation helps and where it stops
Automated tests are still worth having. Tools like Playwright and Cypress are good at repeating the same flow every time someone merges code, and that is exactly what protects you from regressions. Have the model draft them, then review them the way you would review any code: does this test fail when the feature breaks?
What automation cannot do is notice what nobody asked. A script checks the question it was given. A person looks at the screen and thinks “that total seems wrong” or “why can I see this?” or “this button is in the way.” That is exploratory work, and it is the layer that AI-assisted teams tend to skip because the pipeline already looks green. We cover how it works in exploratory testing.
Where a human tester fits
The most useful split is simple. Let the model write the code and a first draft of the tests. Let automation guard what you already know. Then put a human on the product, someone who did not write it and is not trying to prove it works.
That person does a few things well:
- Uses the product the way a customer does, including the wrong way.
- Tests on the real device, not an emulator that is close enough.
- Writes the bug up so a developer can reproduce it on the first try. Here is what a good bug report contains.
- Retests the fix and the things around it.
For a small team, a one-week focused push is often enough to start. A bug bash puts fresh eyes on a release in a short, bounded window.
A simple routine for teams shipping AI-written code
- Write the acceptance criteria in plain language before you prompt the model.
- Review the diff, not just the demo.
- Ask for tests, then read them and break the code on purpose to confirm they fail.
- Run a short manual pass on a real device before every release.
- Keep a list of bugs the model keeps producing, and add each one to your regression checks.
None of this slows you down much. It slows down the kind of bug that ends up in front of a customer.
If you want a person to do that pass for you, Testing Humans rents QA testers from Latin America who work in English, with hours that overlap with the US. You can see the options and prices and pick the smallest one that fits.