wiki / concepts / red-green-tdd
Red/Green TDD
Machine ingest — raw context
loading…
~… tokensappend .md to any wiki URL for this view
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
- Prevents tautological tests: skipping the RED phase risks writing tests that pass trivially without exercising new logic. [source: simon-willison-red-green-tdd-2026]
- Bounds agent scope: the failing test defines exact acceptance criteria, preventing speculative features or unrequested complexity.
- Regression safety: autonomous modifications without a regression suite rapidly break peripheral functionality as the codebase grows.
- 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
| Symptom | Root cause | Fix |
|---|---|---|
| Test passes on first run | Test written after the code (tautology) | Delete it; write the test FIRST against stubbed behavior |
| Agent “fixes” the test instead of the code | Goal inversion under pressure | Rule: implementation changes only until GREEN; test changes need explicit human approval |
| Suite slows to minutes per run | Integration-heavy tests, no unit layer | Keep the RED/GREEN inner loop unit-fast; push integration to a separate suite |
| Red phase skipped under time pressure | Agent treats tests as deliverable, not oracle | Prompt 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.
Related
- simon willison - source of the agentic-engineering pattern
- tdd with agents - broader agent TDD workflow
- eval driven development - TDD generalised to probabilistic systems
- conformance suites as fitness functions - tests as optimization oracles
- agentic manual testing, karpathy four guidelines, agentic engineering patterns
Evidence — verified primary sources
| simon-willison-red-green-tdd-2026 | https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/ | ingested 2026-08-22 sha256:a578765f0bee… |
| kent-beck-gergely-orosz-tdd-ai-agents-2025 | https://newsletter.pragmaticengineer.com/p/tdd-ai-agents-and-coding-with-kent | ingested 2026-08-27 sha256:15b8fadfccc7… |
Graph context
References (5)
Eval-Driven Developmentand tdd-with-agents.Conformance Suites as Fitness FunctionsSimon Willisonsource of the agentic-engineering patternTDD With Agentsbroader agent TDD workflowAgentic Manual Testing, karpathy-four-guidelines, agentic-engineering-patterns Referenced by (9)
Agent Harness EngineeringAgentic Code Quality; evaluate those tests independently.Agentic Engineering Patternstest-driven cycleAgentic Manual TestingConformance Suites as Fitness FunctionsFive Debts of Agentic Engineeringat public seams, agentic-manual-testing, and protected baseline regression suites that remain read-only to the agent.TDD With Agentsand simon-willison's agentic-engineering-patterns.Kent Becktest-driven cyclesSimon Willisontest-driven loops