Autoloop TDD
FeaturedOn demandAbout Autoloop TDD
A manually triggered loop, capped at 12 rounds, that implements a target behavior test-first. Each round writes a failing test, brings the suite to green, then refactors while keeping it passing.
Key features
- 01Fixed red, green, refactor order in every round
- 02New test run on its own before the full suite
- 03Full suite re-run after refactoring
- 04Manual trigger, capped at 12 rounds
Use cases
- 01Developing a new feature test-first
- 02Writing a reproducing failing test before fixing a bug
- 03Tidying a fresh implementation under test protection
- Goal
- The target behavior is implemented test-first and the whole test suite passes.
- Exit when
- Stop when the target behavior is covered by tests and all tests pass.
- Between iterations run
- npm test
Launch prompt
Paste into Claude Code. The agent repeats the steps below until the exit condition is met.
Start the "Autoloop TDD" loop. Goal: The target behavior is implemented test-first and the whole test suite passes. Max iterations: 12. Step 1: Write a failing test — Add a new test for the target behavior and run only that test. It should fail for the expected reason; otherwise fix the test first. `npm test -- --testPathPattern=<new-test>` Step 2: Verify green — Write the smallest implementation that satisfies the test, then run the full suite. The step passes when both the new and existing tests succeed. `npm test` Step 3: Refactor — Clean up the code without changing behavior and run the full suite again. If anything fails, undo or adjust the refactor until the suite is green. `npm test` Between iterations run: `npm test` Exit when: Stop when the target behavior is covered by tests and all tests pass.
Steps
Each round runs in order; if the exit condition isn’t met, another round starts, up to 12.
Add a new test for the target behavior and run only that test. It should fail for the expected reason; otherwise fix the test first.
npm test -- --testPathPattern=<new-test>Write the smallest implementation that satisfies the test, then run the full suite. The step passes when both the new and existing tests succeed.
npm testClean up the code without changing behavior and run the full suite again. If anything fails, undo or adjust the refactor until the suite is green.
npm testSupported agents
Coding agents that can run this loop directly.