The 30-Second Cycle
TDD is not about testing after — it is a design technique. The micro-cycle has three phases: Red (write a test that fails — it documents the desired behavior before the code exists); Green (write the minimum code to make the test pass — no more, no less); Refactor (clean the code without breaking any tests). The entire cycle should take 30 seconds to 3 minutes. If it takes longer, the step is too big.
The Three Laws
Law 1: You may not write production code unless it is to make a failing unit test pass. Law 2: You may not write more of a unit test than is sufficient to fail — and compilation failures count as failures. Law 3: You may not write more production code than is sufficient to pass the one failing unit test. Together these three laws force code and tests to grow in tiny, safe increments.
Code Challenge
Identify the TDD violations in the bad example and apply the three laws in the good version.
Key takeaway
The three laws of TDD are constraints, not suggestions: no production code without a failing test, no bigger test than needed to fail, no bigger implementation than needed to pass.