Executing TDD
TDD is a well-known practice in software engineering. This is a software development approach in which test cases are written first before writing any code for a required feature in an application. Here are the three simple rules of TDD:
- Do not write any functional code unless you write a unit test that is failing.
- Do not write any additional code in the same test more than you need to make the test fail.
- Do not write any functional code more than what is needed to pass a failing test.
These TDD rules also drive us to follow a famous three-phase approach of software development called Red, Green, Refactor. The phases are repeated continuously for TDD. These three phases are shown in Figure 5.4 and are described next.
Red
In this phase, the first step is to write a test without having any code to test. The test will obviously fail in this case. We will not try to write a complete test case but only write enough code to fail the test.