Test Driven Development (TDD) was originally "rediscovered" by Kent Beck in the late 1990s. It is a technique that guides software development by writing tests and boils down to these simple steps:
- Write down test scenarios you want to cover
- Pick a scenario from the list and write a new test for it. Of course, this test will fail initially.
- Write the code you need to make the test and all previous tests pass.
- Refactor the functional code and the tests if you think it improves the code.
- Repeat from step 2
Of course, if you discover new scenarios that should be tested, you should add them to the initial list, regardless of which step you are currently working on.
As with all techniques, it takes practice to become comfortable with TDD. However, we are convinced that it is worth the investment and improves our software design. The benefits become apparent when comparing TDD to the industry practice of writing the tests after the implementation is done. We find these tests harder to write and in our experience they do not provide the same level of confidence if they pass.