Red/Green TDD for Coding Agents
Force agents to write the test first, watch it fail, then pass — the compressed prompt is just 'red/green TDD'.
- Difficulty
- Easy
- Time to result
- ~days to results
- Steps
- 4
- Confidence
- 93%
A discipline for getting reliable output from coding agents by ensuring they actually run the code, using decades-old test-driven development. Agents will write tests on the slightest hint; making them write the test first, watch it fail, implement, then watch it pass produces better code and forces execution. The whole instruction compresses to the jargon phrase 'red/green TDD', which agents understand — a case study in tiny prompts with outsized impact.
Origin
Simon Willison applies the classic red/green TDD practice (long debated among human programmers) specifically to coding agents — noting he personally dislikes writing tests first, but agents don't get bored doing it.
Core principles
- 01The whole point of a coding agent is that it runs the code — if it hasn't, you're back to copy-pasting and hoping
- 02Tests force the agent to at least execute the code, catching syntax errors and giving confidence
- 03Accumulated tests let you add features without manually re-checking everything else for regressions
- 04Dropping tests for speed is a mistake — tests make you faster because you stop worrying about breaking old code
- 05With agents, verbose test suites are now acceptable because updating 1,000 lines of tests is the agent's job, not yours
How to run it
- 1
Require automated tests for essentially every line
Make it the norm that any code released has an automated test proving it works. Agents will write tests the moment you hint at it.
- 2
Instruct the agent to write the test first and watch it fail
Have the agent write the test before the implementation and run it to see it fail — if it passes at this stage, something is wrong.
Watch out Writing this out longhand ('write the test first, then watch it fail, then implement…') is a lot of typing every time.
- 3
Compress the instruction to 'red/green TDD'
Replace the paragraph with the two-word jargon 'red/green TDD', which agents already understand — a 5-second phrase with material impact on results.
Pro tip Willison keeps the exact copy-pasteable markdown for this prompt on his blog.
- 4
Let the accumulated suite guard against regressions
Because the tests live in the repo, telling the agent to change something won't break the features the tests cover — the same benefit human teams get.
Pro tip Tolerate long, verbose suites (100+ tests on a small library) since the agent maintains them, but keep them meaningful tests.
Watch out Don't over-test blindly with thousands of pointless assertions — that is still a bad design pattern, just now a cheaper one to carry.
In the wild
Willison, a former engineer, admits he forced himself to write tests because he'd seen the value but never enjoyed it. Agents write lots of boring boilerplate test code and it just works.
→ He now aims for a test on nearly every line of released code without personally bearing the tedium, and moves faster because regressions are caught automatically.
Common mistakes
Dropping tests because AI codes so fast
Teams that stop testing for speed are wrong — development speed actually goes up with tests because you stop worrying about breaking older features on every change.
Over-testing with meaningless assertions
Thousands of lines of tests that aren't doing anything interesting is still a bad pattern; the cost is lower now but noise remains noise.
Is it for you?
Best for
Anyone using coding agents for real, production-bound software
Not ideal for
Throwaway one-off vibe-coded prototypes where no one will maintain or extend the code
From the transcript
“This is the most important thing when you're working with coding agents is they have to test the code.”
“If you use the term red/green TDD, that's programming jargon which I didn't used to use, but it is jargon for run the test and…”
“updating 1,000 lines of tests is now the job of the coding agent.”
From the episode
An AI state of the union: We’ve passed the inflection point, dark factories are coming, and automation timelines
Simon Willison