Skip to content
dozens edited this page Nov 7, 2025 · 1 revision

Test Driven Design

Three rules of TDD

  1. You are not allowed to write any production code until you have first written a unit test that fails because that code does not exist.

  2. You are not allowed to write more of a unit test than is sufficient to fail, and failing to compile is failing.

  3. You are not allowed to write more production code than is sufficient to make the currently failing test pass.

A little thought will convince you that these three laws will lock you into a cycle that is just a few seconds long. You'll write a line or two of a test that will fail, you'll write a line or two of production code that will pass, around and around every few seconds.

Bob Martin, https://github.com/johnousterhout/aposd-vs-clean-code/blob/main/README.md

Red Green Refactor Loop

A second layer of TDD is the Red-Green-Refactor loop. This loop is several minutes long. It is comprised of a few cycles of the three laws, followed by a period of reflection and refactoring. During that reflection we pull back from the intimacy of the quick cycle and look at the design of the code we've just written. Is it clean? Is it well structured? Is there a better approach? Does it match the design we are pursuing? If not, should it?

Bob Martin, https://github.com/johnousterhout/aposd-vs-clean-code/blob/main/README.md

Clone this wiki locally