---
title: "Red/Green TDD"
description: "Test-first development where failing tests are observed before writing minimal implementation code - the core discipline for coding agents."
section: "concepts"
type: "concept"
created: "2026-08-22"
updated: "2026-08-30"
confidence: "high"
tags: ["tdd", "workflow", "agents", "coding-guidelines"]
canonical: "https://pyweb.dev/wiki/red-green-tdd"
---
# Red/Green TDD

Red/Green Test-Driven Development is the ideal engineering discipline for
coding agents. [[source: simon-willison-red-green-tdd-2026]](/wiki/raw/articles/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](/wiki/eval-driven-development) and [tdd with agents](/wiki/tdd-with-agents).

## The Loop

```text
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]](/wiki/raw/articles/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](/wiki/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](/wiki/simon-willison) - source of the agentic-engineering pattern
- [tdd with agents](/wiki/tdd-with-agents) - broader agent TDD workflow
- [eval driven development](/wiki/eval-driven-development) - TDD generalised to probabilistic systems
- [conformance suites as fitness functions](/wiki/conformance-suites-as-fitness-functions) - tests as optimization oracles
- [agentic manual testing](/wiki/agentic-manual-testing), [karpathy four guidelines](/wiki/karpathy-four-guidelines), [agentic engineering patterns](/wiki/agentic-engineering-patterns)

---

## Agent Navigation

cluster: person (170 pages) | betweenness: 156

### References (outbound)
- [Eval-Driven Development](https://pyweb.dev/wiki/eval-driven-development.md)
- [Conformance Suites as Fitness Functions](https://pyweb.dev/wiki/conformance-suites-as-fitness-functions.md)
- [Simon Willison](https://pyweb.dev/wiki/simon-willison.md)
- [TDD With Agents](https://pyweb.dev/wiki/tdd-with-agents.md)
- [Agentic Manual Testing](https://pyweb.dev/wiki/agentic-manual-testing.md)

### Referenced by (inbound)
- [Agent Harness Engineering](https://pyweb.dev/wiki/agent-harness-engineering.md)
- [Agentic Code Quality](https://pyweb.dev/wiki/agentic-code-quality.md)
- [Agentic Engineering Patterns](https://pyweb.dev/wiki/agentic-engineering-patterns.md)
- [Agentic Manual Testing](https://pyweb.dev/wiki/agentic-manual-testing.md)
- [Conformance Suites as Fitness Functions](https://pyweb.dev/wiki/conformance-suites-as-fitness-functions.md)
- [Five Debts of Agentic Engineering](https://pyweb.dev/wiki/five-debts-of-agentic-engineering.md)
- [TDD With Agents](https://pyweb.dev/wiki/tdd-with-agents.md)
- [Kent Beck](https://pyweb.dev/wiki/kent-beck.md)
- [Simon Willison](https://pyweb.dev/wiki/simon-willison.md)

### Evidence (verified primary sources)
- [simon-willison-red-green-tdd-2026](https://pyweb.dev/wiki/raw/articles/simon-willison-red-green-tdd-2026.md) | origin: https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/ | ingested: 2026-08-22 | sha256: a578765f0bee9430776c214d892afe9fd74dd1b9107a24305f7dd89b4d6e1810
- [kent-beck-gergely-orosz-tdd-ai-agents-2025](https://pyweb.dev/wiki/raw/articles/kent-beck-gergely-orosz-tdd-ai-agents-2025.md) | origin: https://newsletter.pragmaticengineer.com/p/tdd-ai-agents-and-coding-with-kent | ingested: 2026-08-27 | sha256: 15b8fadfccc749c4cdf08351a4c72d217339214a1f2648aa6a124825ee00b312

### Machine endpoints
- Knowledge graph: https://pyweb.dev/api/graph.json
- Graph analysis: https://pyweb.dev/api/graph-analysis.json
- Context index: https://pyweb.dev/llms.txt
