Test-Driven Development (TDD) is a software development approach where you write tests before writing the actual code. It follows a short, repeating cycle often called Red-Green-Refactor:
- Red — Write a failing test that defines the behavior you want.
- Green — Write the minimum amount of code needed to make that test pass.
- Refactor — Clean up the code (and tests) while keeping all tests passing.
The key benefits are that it forces you to think about requirements and edge cases upfront, produces code with high test coverage by default, and makes refactoring safer since you always have a test suite to catch regressions. It also tends to lead to smaller, more modular functions since you’re designing code to be testable from the start.
It’s most commonly associated with unit testing, but the principle can extend to integration and acceptance tests as well (sometimes called BDD or ATDD at higher levels).
Linked Map of Contexts