
AI-Generated Tests: What to Trust, What to Rewrite
Agents can be strong at test breadth yet prone to enshrining bugs, tautologies, and coverage theater. Review criteria for a generated suite and the manual mutation probe.
TL;DR: A working hypothesis, not a documented rule: agents are good at test breadth — enumerating boundary cases, scaffolding fixtures, filling out parametrized suites a human would tire of — and prone to three failures: tests derived from the implementation that enshrine its bugs, tautological assertions that check nothing, and coverage numbers that climb while protection does not. The review criteria are specific: does each test fail when the behavior breaks, are expected values derived independently of the code, and do the names describe behavior. A cheap adequacy check is to break the code on purpose and confirm the suite goes red.
Where agents can help in testing
Start with the strengths, because they are worth using. A working hypothesis, not a documented rule, is that agents are strong at enumerating input-boundary cases — empty, zero, negative, maximum, off-by-one — the tedious perimeter a human tires of before finishing. They scaffold fixtures and mocks quickly, standing up the setup that makes a test possible. And they fill out repetitive parametrized cases without the fatigue that makes a person stop at a few examples when the interesting behavior needed more.
This is not an accident of the domain. Test scaffolding scores high on four properties that make a task a good fit for an agent: it is specifiable (the cases follow from the signature and the spec), verifiable (the tests run), precedented (a working hypothesis, not a documented rule, is that test code is well represented in model training data), and local (each test is self-contained). The realistic framing is that agents can handle test breadth well while test judgment — deciding what matters enough to pin, and what a passing assertion actually needs to prove — remains yours. Breadth without judgment produces a large suite that protects less than its size implies, which is exactly the trap the rest of this comes down to.
The enshrined-bug problem
The most consequential failure is quiet. Ask an agent to write tests for existing code, and it can end up asserting what the code does — including its bugs, now protected by a passing suite. A function that miscalculates a boundary gets a test asserting the miscalculation; the bug is not just present, it is now defended, and any future fix will show up as a test failure that looks like a regression.
The mechanism is worth naming precisely: tests generated from an implementation are characterization tests wearing a unit-test costume. Characterization tests — which Michael Feathers describes as documenting a system's actual behavior rather than checking for the behavior you wish it had — pin current behavior to detect change, and they are useful when you know that is what you are doing. The danger is that agent-generated tests look like specification tests — assertions of what the code should do — while actually being descriptions of what it happens to do, and nobody validated the pinned values against anything but the code itself.
The defense is independent derivation. Expected values come from the spec, from a worked example, from a hand calculation — from any source other than running the code under test and copying its output:
# Enshrines whatever tax() currently returns, bug and all:
def test_tax_bad():
assert tax(100) == tax(100) # asserts nothing
# or: assert tax(100) == 8.4 # value copied from running the code
# Derives the expectation independently, so a wrong implementation fails:
def test_tax_good():
# spec: 8.25% sales tax on the pre-tax amount
assert tax(100) == 8.25 # 100 * 0.0825, computed from the rule, not the codeTautologies and coverage theater
Some generated tests execute code and assert nothing meaningful. The patterns recur and are catchable on sight. The first is the mock-echo: configuring a mock to return a value and then asserting the function returns what the mock was told to return — the test checks little more than that the function passes the mock's value through, so it passes over any implementation that does so, correct or not. The second is logic re-implementation: rewriting the function's computation inside the test and comparing the two, so the test is green whenever the two copies of the same possibly-wrong logic agree.
# Mock-echo: only checks that get_user passes the mock's value through
def test_mock_echo():
repo.find.return_value = {"id": 1, "name": "A"}
assert get_user(1)["name"] == "A" # just re-reads the mock's own value
# Logic re-implementation: compares the code to a copy of itself
def test_reimplements():
assert net(gross, rate) == gross - (gross * rate) # same formula, twiceCoverage theater is the aggregate version of the same problem. Line coverage rises because every line executed, while protection does not, because executing a line is not the same as asserting anything about it — and line coverage is a metric an agent can inflate cheaply, since it rewards touching code, not checking it. The principle underneath the review is assertion quality over assertion count: one assertion that fails when the behavior is wrong outweighs ten that pass regardless.
Reviewing and probing a generated suite
Reviewing a generated suite runs on criteria specific to generated tests, not general review taste. Three questions carry most of it. Does each test fail if the behavior it names breaks — or would it pass over a broken implementation too? Are the expected values derived independently, or copied from the code? Do the test names describe behavior ("rejects an expired token") rather than implementation ("calls validate twice"), since a name that describes mechanics tends to sit over an assertion that checks mechanics.
A cheap adequacy check is a manual mutation probe: on the spots that matter, deliberately break the code under test — flip a comparison, drop a branch, return a constant — and confirm the suite goes red. A suite that stays green while the code is visibly broken is not protecting that behavior, whatever its coverage number says, and this probe finds that out quickly and needs no mutation-testing tool. It answers directly the question a coverage percentage only gestures at.
Pruning is part of accepting the suite, not a separate cleanup. Redundant cases, tautological assertions, and tests that survive the mutation probe unchanged get deleted at review time rather than merged as free coverage. Extra green tests are not a harmless bonus — they add maintenance weight and inflate the confidence the number projects while adding nothing to what is actually guarded. Accepting a generated suite means keeping the assertions that earn their place and removing the ones that only pad the count.