Skip to content

commandTesting

Fix Failing Tests

Runs the suite, groups failures by shared cause and fixes one cause at a time, rerunning after each fix.

npx workspacetemplates add fix-failing-tests --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/fix-failing-tests.md14 lines · 1.1 KBFile
---
description: Runs the suite, groups failures by shared cause and fixes one cause at a time, rerunning after each fix.
argument-hint: "[test path, name pattern or empty for all]"
---

Fix the failing tests. Scope: $ARGUMENTS (the full suite if empty).

1. Find the test command in package.json, Makefile, pyproject or CI config and run it. Save the failing test names and first error line for each.
2. Group failures by cause: same stack frame, same error message, same missing fixture, same changed import. Name each group and count its tests.
3. Take the largest group first. Read the test and the code it exercises and decide whether the code is wrong, the test is stale, or the environment is the problem (time, order, network, missing env var).
4. Fix the root cause with the smallest change. Never delete a test, skip it, loosen an assertion or add retries just to turn it green. If one of those is truly right, explain why and ask.
5. Rerun only the affected tests, then the full suite before moving to the next group.

Finish with a summary: groups fixed, tests per group, what changed, anything still red with your diagnosis. Ask before committing.

What it does

Forty red tests rarely mean forty bugs. This command runs the suite, clusters the failures by root cause and works through the clusters in order of how many tests each one explains.

It decides, for every cluster, whether the code or the test is wrong, and tells you when a fix would mean weakening an assertion.

Example

you › /fix-failing-tests

agent › 31 failing in 4 groups.
1. 19 tests: dateFormat now returns UTC (fixed helper)
2. 8 tests: removed fixture users.json (restored path)
3. 3 tests: stale snapshot of the header (updated after review)
4. 1 test: depends on network, left red with notes.
Suite: 336 pass, 1 fail. Commit?

Questions

Will it skip tests to get green?
No. Skipping, deleting and loosening assertions are off limits unless it explains and you agree.
What if the failure is flaky?
It reruns the test, looks for order or timing dependence and reports it as flaky rather than guessing.
  • Add Edge Case Tests

    CommandTesting

    Free
  • Add Regression Test

    CommandTesting

    Free
  • Coverage Gaps

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free