Testing in an AI-Assisted Pipeline
When an assistant writes the code and the tests, a green build can mean only that the code agrees with itself. This chapter gives a manager a test-first guardrail that keeps people in charge of what counts as correct, four checks that measure whether generated tests can fail, and a one-page gate to put in front of every change.
After this chapter you can
- Explain why tests generated from the code tend to confirm it, and why coverage alone proves little.
- Require a person-approved example table before accepting generated code, approved by someone other than the prompter.
- Run four strength checks on new tests: assertions, red before green, seeded faults and repeat runs.
- Read a mutation score on changed lines and decide what each surviving fault means.
- Set a test gate with named, counted waivers, and treat an assistant editing expected values as a flag.
In a November 2023 test-a-thon (15 to 20 November), 36 engineers at Meta landed 105 unit-test changes for Instagram. Alongside them ran a tool that used a language model to propose more. It created 17 changes, 16 of which landed. One was thrown away. The candidate test did raise coverage, because it executed a method no test had run before, but the engineer reviewing it saw that it contained no assertion1. A line of code had been visited and nothing had been checked. The test would pass whatever the method did.
That small rejection is the whole problem of this chapter. Your engineers now ask an assistant to write a function and then to write its tests. Both arrive in minutes and the build turns green. The question you carry into the review is not whether tests exist. It is whether anyone decided what correct means before the code was drafted, and whether these tests could ever have failed. Level 1 made the general point that quality has to be measured on representative, real work and not on a favorable average; here the same idea is applied to the tests themselves.
Why generated tests tend to confirm the code
A test has two halves: an input and an expected result. The expected result is where the judgment lives. When a person writes it from the requirement, it says what the software should do. When an assistant reads the implementation and writes the test, the easiest source for the expected result is the implementation. The test then describes what the code does, including any mistake in it, and passes on the first run.
Do not overstate this. No study cited here shows that assistant-written tests are worse than human-written ones in general, and an assistant given a clear requirement can write a sharp test. The narrower claim is the one a manager can act on: a passing suite tells you something only if the suite could have failed. The engineering response is to separate two jobs that the assistant has been collapsing, deciding what is correct and writing the code that is checked against it. People keep the first. The assistant can help with the second, and with much of the typing for the first.
The test-first guardrail
The guardrail is a rule about order. Before generated code is accepted for a change, a person-approved statement of the expected behavior exists, in the form of failing tests or at least a table of worked examples. The assistant is then asked to make those examples pass, and anything it adds is judged against them.
There is some evidence that the order helps the model too, within limits. Mathews and Nagappan gave GPT-4 and Llama 3 test cases along with the problem statement on two function-level benchmarks, MBPP and HumanEval, and found that including the tests led to higher success in solving the problems2. Read that for what it is: short functions, two model families, and a benchmark setting. It supports trying test-first with assistants. It does not show the effect on a payment service with six collaborators.
Three details make the rule work in a real team.
- The examples come from the requirement. The product owner, the ticket or an agreed domain rule is the source, not the code. Boundary cases (zero, negative, the last day of the month, empty input) belong in the table because a human reader notices their absence faster than a model does.
- A different person approves the table than prompts the code. One person who both asks for the code and writes the expected values shares one set of blind spots. A second pair of eyes on a table of twelve rows takes minutes.
- The table lands first. It goes into the pull request as its own commit, or a separate small pull request, so the reviewer can read the examples before seeing any implementation.
Four checks that tell you whether tests are strong
Once tests exist, a manager needs a few measurements that do not depend on reading every assertion. Four are cheap enough to run on every change.
Assertions present. The cheapest check is a scan for tests with no assertion, or only trivial ones such as “result is not null”. It is the check that would have caught the rejected Meta candidate before a human had to.
Red before green. Run each new test against the code before the change, or against a deliberately broken version. A test that cannot fail there is not testing the change. Many teams do this by hand for bug fixes already; the guardrail makes it routine for generated tests.
Seeded faults. Mutation testing inserts small faults into the code, such as flipping a comparison or deleting a statement, and counts how many of them the suite detects. Petrovic and Ivankovic describe how Google applied it with a diff-based approach: mutants are limited to the lines a change touches, and the surviving ones are surfaced to authors through code review3. That design is the useful part for a manager, because it keeps the cost proportional to the change and puts the result where decisions already happen. A surviving mutant is a question put to the author: either a behavior is unspecified, or a test is too weak to notice.
Repeat runs. A test that sometimes passes and sometimes fails trains a team to ignore red builds. Meta’s tool discards any generated test that does not pass on every one of five executions1. Five is their number for their setting. Pick a number and apply it.
Why bother with these when the suite is green? Because a green suite can be a weak one, and the effect can be large. The EvalPlus authors extended the HumanEval benchmark with about 80 times more tests, and the pass rates of 26 language models on code generation fell by between 19.3 and 28.9 percent4. Some model rankings changed too. Read the scope: short benchmark functions, and the added tests were themselves generated by model and mutation strategies. The finding is about how much a thin test set can flatter the code it checks. It is not a measurement of your codebase, and it does not say the models were bad. It says the original tests were not strong enough to tell.
What the Meta experience does and does not show
TestGen-LLM is a good case to learn from because its designers built the strength checks into the tool. A candidate test is kept only if it builds, passes on every one of five runs, and increases coverage over the existing tests. On one set of test classes the funnel was steep: 75 percent of generated test cases built correctly, 57 percent passed reliably, and 25 percent added coverage1. Across Instagram and Facebook test-a-thons the tool improved 11.5 percent of the classes it was applied to, and engineers accepted 73 percent of its recommendations for production. In the first Instagram test-a-thon, 36 engineers landed 105 unit test diffs, 16 of them from the tool.
Three limits matter before you borrow the numbers. First, the tool writes regression tests: the filters guarantee a reliable signal that existing behavior has not changed, not that the behavior was right. Second, the acceptance rate comes from test-a-thons, where the paper itself notes that attention to testing was higher than usual, and human reviewers read each diff. Third, it is one company’s account of its own tool. What transfers is the design: a person reviews, and the machine’s output passes mechanical filters first. The funnel also shows how much generated test volume never deserves a reviewer’s time.
Who owns “correct”
The guardrail works only if ownership is explicit. A short division of labor keeps the argument out of review comments.
Two rules are worth writing into your working agreement. The author of a change may not be the only approver of its expected values. And a test that an assistant edits to make a failing build pass is a flag, not a fix: if the assistant changed the expected value, a person decides whether the code or the requirement was wrong.
A team-sized worked example
The numbers below are illustrative, invented for this chapter and not taken from any real team. A team of eight engineers adds a late-fee proration module for invoices. The first draft arrives from an assistant with 28 generated tests, all passing, and a coverage report that looks healthy.
The tech lead applies the gate. The assertion scan finds every test asserting on a result. A seeded-fault run on the changed lines creates 60 mutants; the 28 tests catch 33, a score of 55 percent, so 27 survive. The team’s starting threshold, set by the lead as an illustrative value to be tuned, is 70 percent on changed lines. The gate fails.
Reviewing the 27 survivors takes an hour. Eighteen point to behavior nobody wrote down: what happens when a payment arrives exactly on the due date, how fees round, whether a partial payment resets the clock. The product owner approves a table of 12 examples answering those questions, and 12 new tests are written from the table. The suite now has 40 tests and catches 51 of 60 mutants, 85 percent. Nine mutants survive; the group judges them cosmetic or equivalent to the original code, and records that decision in the pull request.
The cost was about one working day across three people: an hour of survivor review, a short meeting with the product owner and half a day of writing. The release slipped by a week against the optimistic plan, because the table raised questions that the product owner had to answer. In this invented case the delay is the price of the gate; the team judged that those questions would otherwise have turned up later as invoice disputes, which is a judgment, not a measurement.
Make it a gate, with a short pipeline config
A rule that depends on reminders will lapse. Put the checks in the pipeline, and treat the thresholds as starting values you tune with your own data. A sketch in pseudocode:
test-gate: # illustrative starting values; tune per service
require_assertions: true
new_tests_must_fail_on: base_commit
mutation_score_min: 70% # changed lines only
repeat_runs: 5 # any disagreement = flaky, block
example_table: required for new public behavior
waiver: named approver + reason in the pull request
Waivers matter. A gate with no escape hatch gets bypassed in ways you cannot see. A gate whose waivers are named and counted tells you which services have tests that are hard to strengthen, which is a staffing and design conversation.
What this means for engineering managers
Your Monday action (you as owner, the tech lead running the checks): pick the one module that changed most with an assistant last month and ask for the four checks on its latest pull request. Use the template below to record the answers.
Test review note (copy into the pull request)
- Example table approved by: ______ source: ______
- Tests with no assertion: __
- New tests failing on base commit: __ of __
- Mutation score on changed lines: __% (threshold __%), survivors reviewed: __ of __
- Repeat runs (n=__): agree / disagree
- Waiver (name, reason): ______
Check yourself
- If an assistant wrote both the code and its tests and the build is green, the code is correct.
- A generated test that raises coverage but has no assertion should be rejected.
- In the EvalPlus study, adding many more tests to a coding benchmark lowered pass rates across the models tested.
- Mutation testing needs to run on the whole codebase to be useful in review.
- Test-first has been shown to improve assistant output on whole production systems.
Reflection
What comes next
Strong tests make a change checkable. They do not make it small. The next chapter, Small Batches and Pull Request Discipline, covers the size limits and habits that keep AI-assisted changes reviewable in the first place.
References
- Nadia Alshahwan and colleagues. Automated Unit Test Improvement using Large Language Models at Meta. Proceedings of the 32nd ACM International Conference on the Foundations of Software Engineering (FSE 2024); arXiv 2402.09171. 2024.
- Noble Saji Mathews and Meiyappan Nagappan. Test-Driven Development for Code Generation. arXiv 2402.13521 (revised June 2024). 2024.
- Goran Petrovic and Marko Ivankovic. State of Mutation Testing at Google. Proceedings of the 40th International Conference on Software Engineering, Software Engineering in Practice track. 2018.
- Jiawei Liu, Chunqiu Steven Xia, Yuyao Wang and Lingming Zhang. Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation. NeurIPS 2023; arXiv 2305.01210. 2023.
Further reading
- Nadia Alshahwan and colleagues. Automated Unit Test Improvement using Large Language Models at Meta. Proceedings of the 32nd ACM International Conference on the Foundations of Software Engineering (FSE 2024); arXiv 2402.09171. 2024.
- Jiawei Liu, Chunqiu Steven Xia, Yuyao Wang and Lingming Zhang. Is Your Code Generated by ChatGPT Really Correct? Rigorous Evaluation of Large Language Models for Code Generation. NeurIPS 2023; arXiv 2305.01210. 2023.
- Noble Saji Mathews and Meiyappan Nagappan. Test-Driven Development for Code Generation. arXiv 2402.13521 (revised June 2024). 2024.
- Goran Petrovic and Marko Ivankovic. State of Mutation Testing at Google. Proceedings of the 40th International Conference on Software Engineering, Software Engineering in Practice track. 2018.
Sources last verified 2026-10-12.