Guide: Third Law of Test-Driven Development (TDD)
What is the Third Law of TDD?
The Third Law of TDD states: 'You cannot write any production code until you have first written a failing unit test.'
Why is It Important?
It ensures that each piece of production code is sufficiently tested before it is implemented, leading to fewer defects and stronger, more reliable software. This approach minimizes the risk of regression.
How Does It Work?
The developer writes a test that fails, then writes minimum production code to pass the test and refactors the code.
Exam Tips: Answering Questions on Third Law of TDD
1. Understand the fundamental principle: You can't write production code until a test fails.
2. Be able to explain why it's essential: It safeguards against poor code quality and unnecessary features.
3. Be prepared to provide examples of how it is done: Writing a failing test, then production code to pass it.
4. Know the potential outcomes and benefits: This includes fewer bugs, simpler code, and improved design integrity.