- Posted on
- • Background
Better results from AI coding assistants with TDD
- Author
-
-
- User
- maintainer
- Posts by this author
- Posts by this author
-
Update in 26th of April 2026 found simonwillison.net
Initially found on theregister.com
Test driven development (TDD) produces much better results with AI coding assistants:
TDD prevents a failure mode where agents write tests that verify broken behavior. When the tests exist before the code, agents cannot cheat by writing a test that simply confirms whatever incorrect implementation they produced.
Here, for example, is the loop used within the so called red/green TDD:
┌────────────────────┐ ┌──────────────────┐ ┌───────────────────────┐
│ 1. WRITE A LIST ├───► 2. PICK ONE TEST ├───► 3. WRITE THE TEST │
│ OF TEST CASES │ │ exactly one │ │ red │
└────────▲───────────┘ └───────▲──────────┘ └──────────┬────────────┘
│ imrpove │ loop │
┌────────┴───────────┐ ┌───────┴──────────┐ ┌──────────▼────────────┐
│ 5. ADD TO THE LIST ◄───┤ 5. REFACTOR ◄───┤ 4. MAKE THE TEST PASS │
│ as you learn │ │ optionally │ │ green │
└────────────────────┘ └──────────────────┘ └───────────────────────┘
This canonical red/green test driven development was developed as part of Extreme Programming (XP):
- Derive a list of the tests you want to cover from your requirements
- Pick up exactly one test from the list
- Turn this pick into an actual, concrete, runnable test ⇒ flag red (it should fail because implementation is not yet done)
- Change the code to make this test (and all previous tests) pass ⇒ flag green (because at the end the test should pass)
- Optionally refactor your old and newly added code to improve the implementation design
- Add items to the test list as you discover them
- Until the list is empty, go back to step 2
Read more about red/green TDD in
Simon Wilsons Guide for Agentic Engineering Patterns
Martin Fowlers Picture of Test Driven Development
Kent Becks summary of the canonical way to do TDD