📁 Agents
Claude Code Prompt for Testing: Failing Test, Fix, Full Run
A Claude Code prompt that plans tests, writes a failing test first, fixes the code without weakening tests, runs the full suite, and reports evidence.
0Reviews
Prompt
Act as a senior test engineer working inside Claude Code who fixes bugs and adds coverage test-first. You prove each claim with a test run you actually executed in this repo, and you never edit a test just to make it pass. Inputs: - Target code, as @file references or function names: [TargetCode] - The bug report or the behaviors that must hold, written as plain rules: [Behaviors] - Test framework and the exact commands for one file and for the full suite: [TestCommands] - Files or folders you must not change (fixtures, snapshots, generated code, public APIs): [DoNotTouch] - Mocking policy (what may be mocked, what must use real objects): [MockPolicy] Generate: 1. Plan first, no edits: read TargetCode and the existing tests next to it. List each behavior from Behaviors as a test name, plus the edge cases you see (boundaries, empty input, rounding, nulls, time zones). Say which existing test file you will extend. Stop and wait for my OK. 2. Failing tests: after my OK, write only the new tests. Run the single-file command from TestCommands and paste the failure lines. Confirm each new test fails for the reason in Behaviors, not because of a typo or import error. 3. Fix: change only TargetCode. Do not change, skip, or loosen any assertion, and do not touch DoNotTouch. Follow MockPolicy. 4. Prove it: run the single-file command, then the full suite command, and paste the summary lines from both runs. 5. Report: a table of test name, behavior covered, status before fix, status after fix; the diff summary by file; any edge case you noticed but did not test, and why. 6. Suggest one line for CLAUDE.md that would stop this class of bug, for example a rule about boundaries or money in cents. Rules: - If a test cannot fail before the fix, say so and rewrite it until it does. - If the full suite has failures unrelated to this change, list them and leave them alone.
Instructions
Start Claude Code in your repo, switch to plan mode with Shift+Tab, paste this prompt with the brackets filled, and approve the plan before any edits. Review the diff and the pasted test output yourself before you commit.
Generated Output
This image was generated using the prompt above.

Examples
Example Input
TargetCode: @src/cart/shipping.ts, function calculateShipping(subtotalCents: number): number Behaviors: orders of $50.00 or more ship free; orders under $50.00 pay a flat $5.99 shipping fee; amounts are integers in cents. Bug report: a customer with exactly $50.00 in the cart was charged $5.99. TestCommands: one file: npx vitest run src/cart/shipping.test.ts; full suite: npm test DoNotTouch: src/cart/__fixtures__/, any snapshot files MockPolicy: no mocks needed; calculateShipping is a pure function
Example Output
STEP 1: PLAN (no edits yet)
Read src/cart/shipping.ts and src/cart/shipping.test.ts.
Current code: `return subtotalCents > 5000 ? 0 : 599;`
The bug: `>` excludes exactly 5000 cents, so $50.00 is charged.
Planned tests (extending src/cart/shipping.test.ts):
- charges 599 for 4999 cents (just under the line)
- ships free at exactly 5000 cents (the reported bug)
- ships free for 5001 cents
- charges 599 for 0 cents (empty cart)
Edge case noted: amounts are integers in cents, so no rounding test is needed here.
Waiting for your OK.
STEP 2: FAILING TESTS (after OK)
Added 4 tests in a new `describe("free shipping threshold")` block.
Ran: npx vitest run src/cart/shipping.test.ts
FAIL ships free at exactly 5000 cents
AssertionError: expected 599 to be 0
Tests 1 failed | 3 passed (4)
The failure matches the bug report: 5000 cents returns 599 instead of 0. The other three tests pass because the code is already right for them.
STEP 3: FIX
src/cart/shipping.ts: changed `subtotalCents > 5000` to `subtotalCents >= 5000`. Extracted `const FREE_SHIPPING_MIN_CENTS = 5000;` and `const FLAT_SHIPPING_CENTS = 599;` so the rule is readable.
No test or fixture files were changed.
STEP 4: PROOF
Ran: npx vitest run src/cart/shipping.test.ts
Tests 4 passed (4)
Ran: npm test
All test files passed. No unrelated failures.
STEP 5: REPORT
Test | Behavior | Before fix | After fix
charges 599 for 4999 cents | under $50 pays fee | pass | pass
ships free at exactly 5000 cents | $50.00 ships free | FAIL | pass
ships free for 5001 cents | over $50 ships free | pass | pass
charges 599 for 0 cents | empty cart pays fee | pass | pass
Diff: src/cart/shipping.ts (1 condition, 2 constants), src/cart/shipping.test.ts (4 tests).
Not tested: negative amounts. Behaviors do not say what should happen, so I left it for you to decide.
STEP 6: CLAUDE.md SUGGESTION
"Money is integer cents. For every threshold rule, test the value just under, exactly at, and just over the line."