mcpField

Autoloop TDD

FeaturedOn demand
TestingUp to 12 rounds

About 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

  1. 01Fixed red, green, refactor order in every round
  2. 02New test run on its own before the full suite
  3. 03Full suite re-run after refactoring
  4. 04Manual trigger, capped at 12 rounds

Use cases

  1. 01Developing a new feature test-first
  2. 02Writing a reproducing failing test before fixing a bug
  3. 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.

prompt.md
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.

01
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>
02
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
03
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
Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Claude Code
Cursor

Comments

Markdown supported