Skip to content
Guillermo Moral edited this page May 2, 2023 · 7 revisions

The Three laws of TDD

The essence of TDD entails the discipline to do the following:

  1. Create a test suite that enables refactoring and is trusted to the extent the passage implies deployability. That is, if the test suit passes, the system can be deployable.

  2. Create production code that is decoupled enough to be testable and refactorable.

  3. Create a extremely short-cycle feedback loop that maintains the task of writing programs with a stable rhythm and productivity.

  4. Create tests and production code that are sufficiently decoupled from each other so as to allow convenient maintenance of both, without the impediment of replicating changes between the two.

The First Law

Write no production code until you have first written a test that fails due to the lack of that production code.

The Second Law

Write no more of a test that is sufficient to fail or fail to compile. Resolve the failure by writing some production code.

The Third Law

Write no more production code that will resolve the currently failing test. Once the test passes, write more test code.

The Fourth Law

First make it work. then make it right. The law of refactoring. First you write a small amount of failing test code. Then you write a small amount of passing production code. Then you clean up the mess you just made.

RED_GREEN_REFACTOR

Clone this wiki locally