Watch out. Agents can write tests that always pass and add false confidence. The checker step and human review are what make this safe, so never skip them.
Generate and verify tests with agents
One agent writes tests for changed code, another runs them and a third checks they are meaningful.
Best for
- Teams with low test coverage in older code
- Platform teams improving CI quality
- Projects before a major refactor
What you need
- A CI pipeline you can extend
- An existing test framework
- Permission for agents to open, but not merge, pull requests
Starter prompt
Copy it, fill in the parts in square brackets, and paste it into the AI assistant your organisation allows.
You are the test-writing agent for [repository], using [test framework]. For the changed function below, write tests that cover the normal case, edge cases such as empty input and large values, and each error path. Use existing fixtures from [fixture file] where possible. Do not change the function under test. Each test must fail if the function returns the wrong result, so avoid tests that only check it runs. Return only the test file. Function and context: [paste code].
How to use it
1.Scope what agents touch
2.Build the chain
3.Evaluate usefulness
4.Deploy as pull requests
- 1
Scope what agents touch
Allow agents to add test files only, never production code. Choose one service to start.
- 2
Build the chain
A writer agent creates tests, a runner agent executes them in CI, and a checker agent confirms each test fails when the code is deliberately broken.
- 3
Evaluate usefulness
Track how many generated tests catch deliberate bugs. Drop the approach for code where tests are mostly trivial.
- 4
Deploy as pull requests
Have the pipeline open a pull request with the tests and a summary. An engineer reviews and merges.
What you end up with
Meaningful tests added to your codebase through reviewed pull requests.
Related use cases
Understand an unfamiliar codebase faster
Get a plain explanation of a module, its data flow and the risky parts before you change it.
Review pull requests with repo context
An assistant reads the diff, related files and your team's guidelines, then leaves review notes.
Pre-check claim documents before assessment
A pipeline that checks each new claim for missing or mismatched documents and flags it for a person.