What is Test-Driven Development (TDD)?
Answer
Test-Driven Development (TDD) is a software development practice where tests are written before the production code. The cycle: Red: write a failing test that defines the desired behavior. Green: write the minimum code to make the test pass. Refactor: clean up the code while keeping tests green. Repeat. Benefits: (1) Forces good design: code written for testability tends to be more modular and decoupled. (2) Documentation: tests document expected behavior. (3) Regression safety: comprehensive test suite catches regressions. (4) Confidence: refactor safely. (5) Fewer bugs: think through requirements before coding. (6) Feedback: instant feedback on changes. Challenges: learning curve, initial slowdown, tests must be maintained as production code. Not appropriate for all situations (UI prototyping, exploratory work, very uncertain requirements). Created by Kent Beck as part of Extreme Programming.