wiki / concepts / red-green-tdd

Red/Green TDD

high confidence updated 2026-08-30 tdd · workflow · agents · coding-guidelines

Red/Green TDD

Red/Green Test-Driven Development is the ideal engineering discipline for coding agents. [source: simon-willison-red-green-tdd-2026] Prompting an agent with “Use red/green TDD” encapsulates a complete loop: write the test first, observe it fail (RED), write minimal code to make it pass (GREEN), refactor. It is the human-side pattern behind eval driven development and tdd with agents.

The Loop

1. RED    - write a failing test that encodes the next behavior
2. VERIFY - run it; confirm it fails for the expected reason
3. GREEN  - write the minimal implementation that passes
4. REFACTOR - clean up with tests green

Why it is Essential for Agents

  1. Prevents tautological tests: skipping the RED phase risks writing tests that pass trivially without exercising new logic. [source: simon-willison-red-green-tdd-2026]
  2. Bounds agent scope: the failing test defines exact acceptance criteria, preventing speculative features or unrequested complexity.
  3. Regression safety: autonomous modifications without a regression suite rapidly break peripheral functionality as the codebase grows.
  4. Cheap verification oracle: a test suite is a deterministic fitness function - the same property that makes conformance suites as fitness functions work for autonomous optimization loops.

Failure Modes

SymptomRoot causeFix
Test passes on first runTest written after the code (tautology)Delete it; write the test FIRST against stubbed behavior
Agent “fixes” the test instead of the codeGoal inversion under pressureRule: implementation changes only until GREEN; test changes need explicit human approval
Suite slows to minutes per runIntegration-heavy tests, no unit layerKeep the RED/GREEN inner loop unit-fast; push integration to a separate suite
Red phase skipped under time pressureAgent treats tests as deliverable, not oraclePrompt the loop (“confirm the test fails for the expected reason”) not just the style name

Rule of Thumb

If the agent cannot state what the next failing test asserts in one sentence, it is not ready to write code. One behavior, one test, one GREEN.