It is also known as test-driven development (TDD) or test-first programming (TFD).
Test-first development, or test-driven development, is a rapid cycle of testing, coding, and refactoring. When adding a feature, a pair may perform dozens of these cycles, implementing and refining the software in baby steps until there is nothing left to add and nothing left to take away. Kent Beck, who is credited with having developed or 'rediscovered' the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.
It is an evolutionary (iterative and incremental) approach to programming where Agile software developers must first write a test before they write new functional code. It is one of the Extreme Programming(XP) practices.
- Quickly add a test, basically just enough code so that the tests now fail.
- Run the tests, often the complete test suite, although for sake of speed they may run only a subset to ensure that the new test does in fact fail.
- Update the functional code so it passes the new test.
- Run the tests again.
- If the tests fail return to step 3.
- Once the tests pass the next step is to start over (agilists may also want to refactor any duplication out of their design as needed).
Advantages of TDD:
- TDD forces developers to do detailed design just in time (JIT) before writing the code.
- It ensures that agile developers have testing code available to validate their work, ensuring that they test as often and early as possible.
- It gives developers the courage to refactor their code to keep it in the highest quality possible, because they know there is a test suite in place that will detect if they have “broken” anything as the result of refactoring.
- Research shows that TDD substantially reduces the incidence of defects.
- It also helps improve your design, documents your public interfaces, and guards against future mistakes.
I will write more into TDD practices in upcoming posts.