---
title: "Test-first development practice for AI agents | Agentic Pattern Language"
description: "Write the tests first and confirm they fail; the agent then works until they pass. Sourced from Taylor et al., Cursor, and Anthropic."
url: https://agenticpatternlanguage.com/patterns/test-first-development/
---

31 [Practices](https://agenticpatternlanguage.com/#practices)

# Test-first development

Write the tests first and confirm they fail; the agent then works until they pass.

Also called Red/green TDD, Test-driven development

SW KB Taylor et al., Cursor, Anthropic, Simon Willison, Kent Beck

[How to read this](https://agenticpatternlanguage.com/notation/)

## Alternatives

* [Eval-driven development](https://agenticpatternlanguage.com/patterns/eval-driven-development/)

## The problem

An agent may write code that does not work or is never used, and stops when the work only looks done.

> A significant risk with coding agents is that they might write code that doesn't work, or build code that is unnecessary and never gets used, or both.

SW Simon Willison [Red/green TDD - Agentic Engineering Patterns](https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/)

> Claude stops when the work looks done. If it has nothing to run that tells it whether the work actually is done, “looks done” is all it has to go on.

Anthropic [Best practices for Claude Code](https://code.claude.com/docs/en/best-practices)

## Therefore

> Agents perform best when they have a clear target to iterate against. Tests allow the agent to make changes, evaluate results, and incrementally improve until it succeeds.

Cursor [Best practices for coding with agents](https://cursor.com/blog/agent-best-practices) Jan 9, 2026

> Ask Claude to create tests before starting work

Anthropic [Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/multishot-prompting)

> The most disciplined form of TDD is test-first development. You write the automated tests first, confirm that they fail, then iterate on the implementation until the tests pass.

SW Simon Willison [Red/green TDD - Agentic Engineering Patterns](https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/)

## In use

Kent Beck

> You can see from the first commits that I was trying to get the genie to use TDD.

KB Kent Beck [Augmented Coding: Beyond the Vibes](https://tidyfirst.substack.com/p/augmented-coding-beyond-the-vibes) Jun 25, 2025

Simon Willison

> If an agent finds something that doesn't work through their manual testing, I like to tell them to fix it with red/green TDD.

SW Simon Willison [Agentic manual testing - Agentic Engineering Patterns](https://simonwillison.net/guides/agentic-engineering-patterns/agentic-manual-testing/)

Anthropic's Security Engineering team

> The Security Engineering team transformed their workflow from "design doc → janky code → refactor → give up on tests" to asking Claude for pseudocode, guiding it through test-driven development, and checking in periodically.

Anthropic [How Anthropic teams use Claude Code](https://www.anthropic.com/news/how-anthropic-teams-use-claude-code) Jul 24, 2025

## Where it breaks

The agent can bend code to pass the tests or tamper with the tests, or write mock implementations unless told the work is test-first.

> Claude can sometimes focus too heavily on making tests pass at the expense of more general solutions, or might use workarounds such as helper scripts for complex refactoring instead of using standard tools directly.

Anthropic [Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/multishot-prompting)

> Be explicit that you're doing TDD so it avoids creating mock implementations for functionality that doesn't exist yet.

Cursor [Best practices for coding with agents](https://cursor.com/blog/agent-best-practices) Jan 9, 2026

> Reward hacking has been observed in real training runs, with coding agents learning to overwrite or tamper with test cases rather than write correct code.

Taylor et al. [School of Reward Hacks: Hacking harmless tasks generalizes to misaligned behavior in LLMs](https://arxiv.org/abs/2508.17511)

## Sources

1. [School of Reward Hacks: Hacking harmless tasks generalizes to misaligned behavior in LLMs](https://arxiv.org/abs/2508.17511) Mia Taylor, James Chua, Jan Betley, Johannes Treutlein, Owain Evans, Taylor et al.
2. [Best practices for coding with agents](https://cursor.com/blog/agent-best-practices) Lee Robinson, Cursor, Jan 9, 2026
3. [How Anthropic teams use Claude Code](https://www.anthropic.com/news/how-anthropic-teams-use-claude-code) Anthropic, Jul 24, 2025
4. [Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/multishot-prompting) Anthropic
5. [Best practices for Claude Code](https://code.claude.com/docs/en/best-practices) Anthropic
6. [Red/green TDD - Agentic Engineering Patterns](https://simonwillison.net/guides/agentic-engineering-patterns/red-green-tdd/) Simon Willison
   > Every good model understands "red/green TDD" as a shorthand for the much longer "use test driven development, write the tests first, confirm that the tests fail before you implement the change that gets them to pass".
7. [Augmented Coding: Beyond the Vibes](https://tidyfirst.substack.com/p/augmented-coding-beyond-the-vibes) Kent Beck, Jun 25, 2025
8. [Agentic manual testing - Agentic Engineering Patterns](https://simonwillison.net/guides/agentic-engineering-patterns/agentic-manual-testing/) Simon Willison

Added Nov 14, 2026
