Test Driven Development (TDD) is a practice of Extreme Programming consisting in writing tests before production code to guarantee the code quality.
Development process is divided in 3 steps:
- Red: write a failing test
- Green: write the minimum production code required to make the test pass, all shortcuts are allowed
- Refactor: clean the mess of the code you just wrote to make it clean, improve the design
Since no production code is added before a test covers a usecase, test coverage is as close as possible to 100%.
Moreover, TDD promotes the usage of clean code principles thanks to the refactoring stage.
It can also help to make a clean design appear progressively. As Uncle Bob says: "as the tests become more specific, the code becomes more generic".
TDD helps team to write code that is easier to maintain and less risky to deliver.
TDD is often difficult to learn, especially on real life projects. Code katas are helpful to master this practice progressively with more simple use cases.