Example result: Let an AI agent fix failing tests properly
AI-generated example · Agent · Fix Tests
Updated

Let an AI agent fix failing tests properly

This prompt tells Claude Code or Cursor to run your tests and fix the failures the right way. It must explain each failure first and must never delete, skip or weaken a test just to make it pass.

text-code-fix-failing-tests-agent — claude code — 98 words

Run [TEST COMMAND, e.g. npm test] and fix the failing tests.

Rules:
- Find out why each test fails before changing anything.
- If the code is wrong, fix the code. If the test is outdated, explain why before changing it.
- Never delete a test, skip it, or loosen an assertion just to make it pass.
- Keep changes small and run the tests again after each fix.

When everything passes, give me a short list of each failure, its cause and the fix, and point out anything that looks like a real bug in the product.

The "never delete or skip a test" line matters. Without it, agents sometimes make tests pass the easy way.

Get a better result

What you will get

A working session in which the agent runs your tests, finds the cause of each failure, fixes the code or explains why a test is out of date, re-runs after each change and ends with a short list of failures, causes and fixes.

Common mistake

Snapshot tests are updated blindly so that they pass.

Fix: Add “never update a snapshot without first showing me the diff and explaining why the new output is correct”.

Also watch for
  • It runs only the failing test, then a fix breaks another one. Add “at the end run the full suite and paste its summary line”. A green single test proves little.
  • A flaky or environment-related test is “fixed” by changing real code. Say “if a test passes on a re-run with no change, report it as flaky and do not change the product code”.
Try a variation: diagnose only

Use “do not edit any file. For each failing test, give the cause, the file and line, and the change you would make”. You review the plan first, then let the agent apply it.

Still not right? Reply with this

Stop and show me the diff for any snapshot or test you changed, explain why the new output is right, then run the whole suite and paste the summary line.

Guides that use this prompt

More chat & writing prompts

See all 465 →