Skip to content

Generate and verify tests with agents

One agent writes tests for changed code, another runs them and a third checks they are meaningful.

Recommended: ArchitectAgentsAutomation

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. 1.Scope what agents touch

  2. 2.Build the chain

  3. 3.Evaluate usefulness

  4. 4.Deploy as pull requests

  1. 1

    Scope what agents touch

    Allow agents to add test files only, never production code. Choose one service to start.

  2. 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. 3

    Evaluate usefulness

    Track how many generated tests catch deliberate bugs. Drop the approach for code where tests are mostly trivial.

  4. 4

    Deploy as pull requests

    Have the pipeline open a pull request with the tests and a summary. An engineer reviews and merges.

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.

What you end up with

Meaningful tests added to your codebase through reviewed pull requests.

Read why AI matters in software engineering

Related use cases