Skip to content
Hiep Lam
Go back

Beyond Coverage, Part 5: Grading AI-Generated Tests

Edit page 🇻🇳 Tiếng Việt

“Beyond Coverage: Test Quality for the Agentic Loop” - Part 5 of 7. This is the part the whole series has been building toward: how to grade a test an AI wrote, so a merge gate can trust it without a human re-checking every case by hand.

Raw LLM-generated tests are roughly half junk (compile failures, flakes, vacuous asserts), and the ones that look fine carry a unique danger: they tend to assert what the code currently does - locking in existing bugs. The fix is a filter gauntlet modeled on Meta’s TestGen-LLM: a test is admitted only if it builds, passes, is stable, and kills a mutant no existing test killed - and behaviour-defining oracles on critical paths are owned by a spec/human, not the model.


How bad is raw LLM test output?

Meta’s TestGen-LLM (the most authoritative industrial data point) measured its own raw output: only 75% of generated test cases built correctly, and only 57% passed reliably. [testgen] Nearly half of raw output is non-functional before you even ask whether it tests anything meaningful.

And the survivors have characteristic defects:

So “the AI wrote tests and coverage went up” is not evidence of safety. It may be evidence of vacuous tests that execute code and assert nothing - the exact Goodhart failure from Part 0.

The unique danger: bug-locking oracles

This is the one that will bite an autonomous loop hardest. LLMs generating test oracles (the assertions) are “biased toward the actual (possibly buggy) implementation rather than the intended behaviour” - their oracle-classification accuracy “considerably drops in the presence of buggy code.” [bias]

Concretely: point an LLM at a function that computes commission slightly wrong, and it will happily write Assert.Equal(wrongValue, result) - a test that passes, raises coverage, and permanently cements the bug. Worse, every future correct change now “breaks a test,” so the agent (or a tired human) will tend to update the test to match the buggy code rather than fix the code.

The defense: the oracle for behaviour that matters must come from the specification, not the current code. On critical paths, a human (or a spec/property the human wrote) defines what’s correct; the AI may write the scaffolding and edge cases, but it does not get to define truth for money/auth/data-loss logic.

Why you must NOT gate AI tests on coverage

The instinct is “accept the AI test if it raises coverage.” The data says that throws away your best tests. In Meta’s mutation-guided runs, of 571 tests that caught faults missed by every existing test, 277 (~half) added zero new line coverage. A coverage-gated pipeline would have discarded half of the genuinely fault-finding tests. [coverage-discard]

Gate AI tests on mutants killed, not on coverage gained. A test that kills a previously-surviving mutant is provably strengthening your oracle. A test that only adds coverage is, at best, reachability - and at worst, vacuous.

The grading gauntlet (use this as your accept/reject pipeline)

A machine-generated test is admitted to the suite only if it clears every gate:

#GateReject if…How
1Buildswon’t compileCI build
2Passesred on first runrun once
3Stableflakyrun 5×, require identical result [testgen]
4Strengthens ★kills no new mutantrun mutation on the diff; require ≥1 newly-killed mutant
5Cleanhas a test smellscan: no assertion-free / magic-number / conditional-logic / act-assert-mismatch
6Behavioural oracleasserts implementation, not specon critical paths, oracle traces to a human-owned spec/property, not “current output”

The AI-generated-test gauntlet: six gates a candidate test must clear before it merges Never trust raw LLM output. Only a test that survives every filter earns a place in the suite (after Meta’s TestGen-LLM, FSE 2024).

Gates 1–3 are Meta’s published filter (build → pass → no-flake). Gate 4 is the one most teams skip and the one that actually separates a real test from a vacuous one. Gates 5–6 defend against the AI-specific failure modes above.

This is the operational meaning of “Assured LLM-based Software Engineering”: never trust raw model output - keep only changes whose value is mechanically measured.

What this gets you toward the full loop

The goal is to trust AI-generated tests enough to skip manual testing before merge. That is achievable, but the trust is earned by the gauntlet, not by the model:

In this design you’re not trusting the AI’s judgment - you’re trusting a measurement the AI has to satisfy. That’s the difference between “vibe-merging” and an autonomous loop you can defend. The final part turns this into concrete thresholds and a maturity ladder.


Sources


← Previous: Part 4 - Tooling for Go and .NET · Next: Part 6 - The Readiness Rubric →

The series - Beyond Coverage: Test Quality for the Agentic Loop: 0 · Why Coverage Lies · 1 · The Metric Catalog · 2 · Mutation Testing, Properly Explained · 3 · What the Empirical Research Actually Says · 4 · Tooling for Go and .NET · 5 · Grading AI-Generated Tests (you are here) · 6 · The Readiness Rubric


Edit page
Share this post:

Previous Post
Beyond Coverage, Part 4: Tooling for Go and .NET
Next Post
Beyond Coverage, Part 6: The Agentic Merge-Gate Readiness Rubric

Keep reading

A few more pieces in the same vein.

Rather read on your own time? Subscribe via RSS