Skip to content
SeedlingConcept

Test-First Programming

planted Aug 7, 2026 · last tended Aug 7, 2026

Test-First Programming is one of XP‘s thirteen primary practices: write a failing automated test, then write only the code that makes it pass. Martin Fowler’s canonical cycle is three steps, “Red, Green, Refactor”: write a test for the next bit of functionality, write the functional code until it passes, then refactor both new and old code.

The name in the book is Test-First Programming, not Test-Driven Development. The distinction is worth keeping. Test-first is the XP practice, sitting among twelve others and justified by the values it serves. TDD is the technique extracted from it, which Beck later gave its own book, and which travels into teams that run none of the rest of XP.

It is a design practice

The regression suite is a by-product. The reason the test comes first, in Fowler’s phrasing, is that it “forces us to think about the interface to the code first”, separating interface from implementation before you have committed to either. Test-first is where the difficulty of writing a test becomes design feedback rather than a chore, which is exactly the argument behind writable tests.

Fowler names the usual failure directly: the most common way to get TDD wrong is neglecting the third step. Skip the refactor and you get covered mess.

What it needs from the tests

Test-first only stays affordable if the resulting tests have the right properties. They must be fast, because the cycle runs many times an hour. They must be deterministic, because a red bar you cannot trust destroys the whole loop. And they should be behavioral rather than coupled to structure, or the refactor step in the cycle starts breaking the tests that were meant to protect it. The full set is the test desiderata.

Signal: you have watched the test fail for the right reason before making it pass, and you refactor with the bar green.

Sources

  • Kent Beck with Cynthia Andres, Extreme Programming Explained: Embrace Change, 2nd edition (Addison-Wesley, 2004): Test-First Programming is listed as a primary practice in chapter 7, per the published table of contents.
  • Martin Fowler, Test Driven Development: the Red/Green/Refactor cycle, TDD’s origin “as part of Extreme Programming”, the interface-first design argument, and the neglected-refactor failure mode.