AI generated tests: the coverage number that doesn't mean what you think
The green report that means nothing
You point a coding assistant at an undertested module, ask it to write tests, and twenty minutes later your coverage report jumps from 41% to 89%. It feels like progress. CI turns green. You merge it and move on.
Then three weeks later the same function ships a bug that was sitting there the whole time, in a branch the new tests technically executed but never actually checked. That’s close to the default outcome when you ask an LLM to generate a test suite for code it didn’t write and has no spec for, and it comes down to a mechanical fact about how these tools work, not a quality issue you can prompt your way out of.
How the generation actually happens
When you ask a coding assistant to write tests for a function, it doesn’t have access to what the function is supposed to do. It has the function itself, maybe a docstring, maybe some surrounding calls. It reads the implementation, runs it mentally (or literally, if the tool has a code execution sandbox), and writes assertions that match what it observes.
That’s the whole mechanism. The model is describing the code’s current behavior back to you in test form. If the function is correct, this produces a reasonable regression suite. If the function has a bug, the model has no way to know that, because the bug and the “correct” behavior look identical from where it’s sitting. It will happily write expect(divide(10, 0)).toEqual(Infinity) if that’s what the code returns, because nothing in its context tells it that should have been a guarded exception instead.
This is different from a human writing tests from a spec or a ticket. A human test author usually has some independent idea of what should happen. An LLM generating tests from source alone only has what does happen. The tests it produces are a mirror, not a check.
Why coverage percentage goes up without bug-catching going up
Line and branch coverage measure execution, not correctness. A test that calls a function and asserts nothing more than “it didn’t throw” will mark every line it touches as covered. AI-generated suites lean on this kind of assertion constantly, because it’s the safest thing to write when you don’t know what the “right” answer is supposed to be: check the type of the return value, check it’s not null, check the function exits without an exception. These pass instantly, they inflate the coverage number, and they catch almost nothing.
You can see this gap directly with mutation testing, which is a much older idea than AI test generation and existed specifically because coverage percentage was already being gamed by humans writing lazy tests. Tools like Stryker, PIT, or mutmut take your code, introduce small deliberate bugs (flip a > to >=, swap a + for a -, delete a conditional), and rerun your test suite against each mutant. If your tests still pass, that mutant “survived,” which means nothing in your suite actually depends on that piece of logic being correct. A suite can sit at 90% line coverage and still let the majority of mutants survive, because coverage only asks “did we run this line,” and mutation testing asks “does anything care what this line does.” Those are different questions, and AI-generated tests are optimized, by construction, to answer the first one well and the second one poorly.
The mirror problem in practice
The failure mode that actually bites you in production shows up when you point the assistant at code you assume is fine: it generates a clean-looking suite, and that suite locks in whatever bug was already there. Now the bug has a green checkmark next to it. Anyone who touches that function later and accidentally fixes the bug will watch CI fail, because the “expected” value baked into the AI-written test is the wrong one.
This is worse than having no test at all in one specific way: no test is an honest admission of unknown behavior, while a wrong test is a false claim of verified behavior. It changes how the next engineer reads the code. They see a passing test and reasonably assume someone checked the logic, when what actually happened is a model described the logic back to itself.
Where it genuinely earns its keep
None of this means AI test generation is a waste of tokens. It’s good at things that don’t require knowing intent.
Boilerplate and parameterization is the clearest win: given one well-written test case, an assistant can reliably expand it into a matrix of edge cases (empty string, null, max int, unicode, negative numbers) faster than typing them out by hand. You’re not asking it to invent correctness, you’re asking it to enumerate variations on a pattern you already validated.
Legacy code with zero tests is another good fit, specifically as a characterization test rather than a correctness check. If you’re about to refactor a function nobody trusts and nobody has time to fully spec, an AI-generated suite that pins down current behavior gives you a tripwire for the refactor: if your rewrite changes an output, you’ll know immediately, even if you can’t say for certain the original output was right. You’re using the mirror property on purpose here instead of getting burned by it.
It also speeds up the mechanical parts of test writing that eat real time: mock setup, fixture data, assertion syntax for a framework you don’t use daily. That’s scaffolding, and scaffolding is exactly the kind of work LLMs are reliable at.
What to actually check before merging an AI-written suite
Run mutation testing on the file if the codebase already has it wired in, and treat a high mutant-survival rate as a real signal, not noise. If it’s not wired in, at minimum hand-mutate two or three lines yourself, rerun the suite, and confirm it fails. If flipping a comparison operator or deleting a conditional doesn’t break a single test, the coverage number is decorative.
Read the assertions, not the test count. A file with forty new tests and a file with eight new tests can carry the same amount of actual verification, depending on whether those forty are checking specific values or just checking “no exception was thrown.” Skim for toBeDefined, not.toBeNull, assert response.status_code, and similar catch-all checks. They’re better than nothing. They just shouldn’t be the only thing standing between you and a bug.
Ask for the test before the fix, not after, when you already suspect a bug. If you generate tests against code you know is broken, you’ll get a suite that faithfully documents the breakage. Fix first, or write the specific regression test by hand, then let the assistant fill in the surrounding cases.
The bottom line
AI test generation is fast at producing something that looks like verification and is often only producing documentation of current behavior, bugs included. The coverage report can’t tell the difference, because it was never designed to. Mutation testing can, roughly, and a careful read of the actual assertions can too. Use the assistant for scaffolding, edge case enumeration, and characterization tests on legacy code, and keep the correctness judgment where it belongs, with an engineer who knows what the function was supposed to do in the first place.
Want more breakdowns like this on what AI coding tools actually do under the hood, not what the marketing says? Head back to the AI Tool Gazette homepage for the rest of our coverage.