Blog

How to fix failing tests with an AI coding agent

A list of test results with passing checkmarks and one failing cross

Failing tests are one of the best jobs to hand to a coding agent. The failure is already a precise description of the problem. The risk is a fix that makes the test pass without fixing the code.

What should I give the agent first?

The exact failing output and the command that produced it. Add the test name or file. Do not paste the whole log if only one test fails. Less text means fewer tokens and a clearer target.

What order of steps works?

  1. Run the tests and pick one failing test.
  2. Ask the agent to find the cause before changing anything.
  3. Ask for the smallest fix, as a diff.
  4. Run the same test, then the wider suite.

How do I stop it gaming the test?

Tell it not to edit the test unless the test is wrong, and ask it to say why. Then read the diff. A fix that special-cases the test input is a red flag. Use the checklist in reviewing AI-written code before you commit.

What if it keeps failing?

Narrow the request, give the one file that matters, or restart the session with the last result. A fresh start often beats a long thread.

Start from a real failing test: create a Toknary account.

Keep reading

Try Toknary freeAll guides