The ingredients of the TDD pill are as follows and should be prepared following the given order exactly:
Choose a small task.
Write a test for that task.
Run all the tests to verify that the new test fails.
Write minimal production code to complete the task.
Run all tests (including the new one) to verify that they pass.
Refactor the code as necessary.
Repeat from step 1.
The active ingredient in the TDD pill is the authoring of test cases before production code. Authoring test cases before code requires the patient to consider the design of the solution, how information will flow, the possible outputs of the code, and exceptional scenarios that might occur. Running the newly written test case before writing production code helps to verify that the test is written correctly (a passing test case at this point is not testing the intended effects) and that the system compiles. The TDD pill also involves writing just enough production code to pass the test case, which encourages an uncluttered, modular design. Furthermore, TDD users create a growing library of automated test cases that can be executed at any time to verify the correctness of the existing system whenever changes are made.
Like many drugs, the TDD pill has some official variants, including ATDD (Acceptance-Test-Driven Development), BDD (Behavior-Driven Development) and STDD (Story-Test-Driven Development). ATDD replaces the “small task” step with “functional level business logic tasks,” whereas BDD uses ...