Skip to content

commandTesting

Add Regression Test

Writes a test that fails on the bug you describe, proves it fails, then confirms it passes once the fix is in.

npx workspacetemplates add add-regression-test --tool claude-code

Writes 1 file to .claude/commands/

.claude/commands/add-regression-test.md15 lines · 1.2 KBFile
---
description: Writes a test that fails on the bug you describe, proves it fails, then confirms it passes once the fix is in.
argument-hint: "[bug description or issue number]"
---

Add a regression test for this bug: $ARGUMENTS

1. Restate the bug as input, expected result and actual result. If any of the three is unclear, ask one question and wait.
2. Find the code responsible and the nearest existing test file. Copy its naming, fixtures and assertion style. Do not add a new framework.
3. Write the smallest test that reproduces the bug at the lowest level possible (unit before integration). Use a name that states the behavior, not the ticket number alone.
4. Run it before any fix. It must fail, and the failure message must show the bug itself, not a typo or missing import. If it passes, the bug is not reproduced: say so and investigate.
5. If a fix is not in yet, show the proposed fix and ask before editing source. If it is already in, check out the previous version of the file with `git stash` or `git show` to confirm the test fails there.
6. Run the test again with the fix, then the surrounding test file.

Report: test file and name, red output, green output, and the one-line cause.

What it does

A bug fix without a test tends to come back. This command turns a bug report into the smallest test that reproduces it, runs it to see it fail for the right reason and only then lets the fix go in.

The test is placed beside the existing ones in their style, and the report shows the red run and the green run so the evidence is visible.

Example

you › /add-regression-test totals double count a coupon when the cart has one item

agent › Added test "applies a coupon once for single-item carts" in cart.test.ts.
Before fix: expected 90, received 80.
After the proposed fix in applyCoupon(): pass, 24 of 24 tests in the file green.
Apply the fix?

Questions

Why must the test fail first?
A test that never failed proves nothing. The red run shows it really catches the bug.
Does it fix the bug too?
It proposes the fix and asks first, or checks the test against a fix you already made.
  • Add Edge Case Tests

    CommandTesting

    Free
  • Coverage Gaps

    CommandTesting

    Free
  • E2E Scenario

    CommandTesting

    Free
  • Fix Failing Tests

    CommandTesting

    Free