The “3 rules of TDD” is hard to understand. Let me rephrase it a bit.
1 min readMar 19, 2022
Uncle Bob’s The Three Rules Of TDD helps guide us do TDD (Test-driven development) better. These are the rules:
- You are not allowed to write any production code unless it is to make a failing unit test pass.
- You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
- You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
I find them hard to understand. Those NOT and UNLESS words take my brain 10 minutes and 10kcal of energy just to understand one of them. I think it is easier to understand if we rephrase them like this:
- If all tests are passing, don’t write more code.
- If any test is failing, don’t write more test. Fix code to make tests pass.
- Go read number 1.
And after all functionalities are implemented, you refactor the code.
Now that’s better! 😆 I hope it will help you remember it easier.