---
title: "TDD inside the agent loop - theater or actual value?"
url: https://daily.dev/posts/tdd-inside-the-agent-loop---theater-or-actual-value--mytwhkuys
source_url: https://martinfowler.com/articles/exploring-gen-ai/tdd-in-the-agent-loop.html
type: article
source: "Martin Fowler"
published: 2026-08-11T11:45:02.707Z
updated: 2026-08-11T11:45:38.143Z
tags: ["python", "testing", "ai-agents", "tdd", "mutation-testing"]
reading_time: 22
upvotes: 1
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# TDD inside the agent loop - theater or actual value?

**[Martin Fowler](https://daily.dev/sources/mafo)** · 22 min read · 1 upvotes · 0 comments

## Summary

An exploratory evaluation of whether TDD inside an AI agent loop provides real value or is merely theater. Using Claude Sonnet 4.6 to generate solutions and Opus 4.8 as judge, the author ran TDD vs. non-TDD coding sessions across small, medium, and large Python tasks. Results showed no clear quality advantage for TDD: non-TDD solutions were ranked #1 and #2 in most batches, and mutation scores showed no meaningful difference. TDD sessions consumed 3-8x more tokens. The core hypothesis: agents lack the upfront design step that non-TDD runs naturally perform, and LLMs are trained on completed code rather than step-by-step TDD processes. The author concludes that classic TDD goals (avoiding tautology, driving design, YAGNI, managing fear) largely don't transfer to the agent loop, and recommends focusing on outcome monitoring via mutation testing and static analysis instead of prescribing TDD workflow to agents.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://martinfowler.com/articles/exploring-gen-ai/tdd-in-the-agent-loop.html>

## Questions this post answers

### Does using TDD instructions with an AI coding agent produce better code quality than no TDD?

Based on a structured evaluation using Claude Sonnet 4.6 for code generation and Opus 4.8 as judge, TDD instructions produced no clear quality advantage. Non-TDD solutions ranked #1 and #2 in most batches across small and medium tasks. Mutation scores were also comparable. The likely reason: non-TDD agents perform full upfront design before writing any code, while TDD constrains design to emerge one test at a time.

_Engineers weighing TDD prompts for their agent workflows track findings like these on daily.dev._

### How many more tokens does a TDD agent workflow use compared to no TDD?

TDD agent sessions used roughly 3–8.5x more tokens than non-TDD sessions. For small tasks the factor was 8.5x (119K vs 1M tokens), for medium tasks ~3x (736K vs 2.18M), and for large tasks ~4.9x (254K vs 1.24M). Many of those extra tokens are cache reads, so the true dollar cost increase is lower than the raw multiplier suggests.

_Teams budgeting AI coding agent usage can find cost-vs-quality tradeoff discussions like this on daily.dev._

### Why do AI agents struggle to follow TDD correctly even when instructed to?

AI agents frequently write the implementation first and generate tests after, skip confirming the red step, or over-implement ahead of the current test so the next one passes without going red. One theory: LLMs are trained predominantly on completed functions paired with descriptions, not on step-by-step TDD examples, so their internal representation maps requirements directly to code rather than modeling the TDD process.

_Developers building reliable agent prompts for software delivery keep up with research like this on daily.dev._

## Similar posts on daily.dev

- [TDD is more important than ever](https://daily.dev/posts/tdd-is-more-important-than-ever-hoeecbmpk) · Justin Searls · 118 upvotes · 8 comments
- [Dual-loop BDD is the new Red-green TDD](https://daily.dev/posts/dual-loop-bdd-is-the-new-red-green-tdd-idl5bpq1q) · Justin Searls · 3 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#testing](https://daily.dev/tags/testing), [#ai-agents](https://daily.dev/tags/ai-agents), [#tdd](https://daily.dev/tags/tdd), [#mutation-testing](https://daily.dev/tags/mutation-testing)

[View this post on daily.dev](https://daily.dev/posts/tdd-inside-the-agent-loop---theater-or-actual-value--mytwhkuys)
