Engineering
An AI agent to write unit tests for the paths your coverage keeps missing, proving each one fails without the fix before it offers it to a human.
What an AI agent to write unit tests does
An AI agent to write unit tests is a scoped autonomous worker that finds untested paths, writes tests for them, verifies those tests actually detect a defect, and proposes them as a normal contribution for review.
The verification step is the whole point. Generated tests are easy to produce and mostly worthless, because a test that passes against broken code is worse than no test at all: it converts an absence of coverage into a false sense of it. This agent mutates the code under test and discards any test that still passes. Only tests that genuinely fail without the fix are ever proposed.
It works on the paths nobody gets to. The error branch, the boundary condition, the retry logic, the code written under deadline eighteen months ago that everyone is now slightly afraid of.
Inputs -> Outputs
| It reads | It produces |
|---|---|
| Coverage reports and untested branches | Tests for the paths with the highest risk-to-effort ratio |
| The code under test and its callers | Tests written in your existing framework and idiom |
| Your test conventions and fixtures | Reuse of your fixtures rather than a parallel set |
| Mutation results | A discard of every test that survives a mutated defect |
| Flake history | A quarantine flag on tests that pass and fail without a code change |
| The coverage gate | An escalation when a merge would drop coverage below it |
Where it runs
- Code repositories and pull requests
- CI/CD pipelines
- Coverage and mutation tooling
- Test frameworks
- Issue trackers
- Chat, for the nightly summary
Platform names are shown as illustrative examples of a category, never a claim of a delivered integration.
A day in its life
| Time | What it does |
|---|---|
| 01:00 | The nightly run starts. It pulls the coverage report and ranks untested branches by risk. |
| 01:06 | It picks the payment retry path: uncovered, frequently changed, expensive when wrong. |
| 01:11 | It writes four tests in your framework, reusing your existing fixtures. |
| 01:14 | It mutates the retry logic. Three tests fail as they should. One passes and is discarded. |
| 01:20 | It opens a pull request with the three surviving tests and the mutation evidence attached. |
| 09:30 | An engineer reads the evidence, adjusts one assertion and merges. Coverage moves where it matters. |
Guardrails and human-in-the-loop
Autonomy boundary
It may read code, write tests, run them and open a pull request. It may not modify production code, weaken an assertion, delete an existing test or merge.
Approval gates
Every test reaches the codebase through your normal review, because a test is code and is maintained like code.
What stays human
Deciding what behavior is correct. The agent tests what the code does; only a person can say whether that is what it should do.
Escalation
If a proposed test reveals what looks like a genuine defect rather than a coverage gap, it stops and raises it instead of quietly encoding the bug as expected behavior.
Logging
Every proposed test carries its mutation evidence, so a reviewer can see why it is worth having.
The human role it augments
This agent does not replace your engineers’ judgment about correctness. It removes the part of testing everybody agrees is necessary and nobody schedules: the backfill on old code, the error branches, the boundary cases. Your engineers keep writing the tests that encode intent for new work, which is the part that genuinely needs a person who knows what the feature is for.
It also changes an argument into a number. “We should improve coverage” becomes a nightly pull request with evidence, which is a much easier thing to prioritize than a vague intention.
Time to value and cost shape
- Cost shape - Priced per run rather than per engineer seat. The comparison is the engineering hours a coverage backfill would otherwise consume, against the cost of defects that reach production because the branch was never tested.
- Model your own figures - ROI calculator · what a hive costs
KPIs it moves
- Coverage on risk paths
- Movement on the branches that matter, not the headline percentage (Yours)
- Mutation-verified
- Every proposed test proven to fail without the fix (Target)
- Test acceptance rate
- Share of proposed tests merged. A falling rate is a defect (Target)
- Flake quarantine
- Unstable tests identified rather than left to erode trust (Target)
Provenance is shown on every cell. Nothing here is a client outcome.
Frequently asked questions
Are generated tests actually worth having?
Only if they can fail, which is why every test is mutation-verified before it is proposed. The agent introduces a defect into the code under test and discards any test that still passes. A test that passes against broken code is worse than no test, because it creates confidence that is not earned.
Will it just chase a coverage percentage?
No, and we would treat that as a failure mode. It ranks untested paths by risk and change frequency, so it works on the payment retry rather than a trivial getter. Coverage percentage is a side effect of testing the right things, not the target.
What if it writes a test that encodes a bug as correct behavior?
That is the real risk with generated tests, and it is why the agent stops when a proposed test looks like it is documenting a defect rather than a gap. It raises the discrepancy for a human instead of encoding it. Reviewers still decide what correct means.
Can it work on a legacy codebase with no tests at all?
That is usually where it pays off most, because the barrier there is starting rather than skill. It builds fixtures as it goes and works module by module. Expect the first weeks to be slower while conventions are established, since there are none to copy.
Related agents
Incident Response Agent
Handles the defects tests did not catch.
Self-Healing Infra Agent
Repairs the environment tests run in.
Dependency & Patch Agent
Relies on these tests to prove a patch is safe.
Build & Release Agent
Reports the flakes this agent quarantines.
Code Review Agent
Flags the untested branches this agent then covers.
Social Scheduler Agent
A different department, same pattern: propose, never publish.



