What is Test-Driven Development (TDD) in an Agile context?
Answer
Test-Driven Development (TDD) is a software development practice (from XP) where tests are written before the code they test. The TDD cycle: (1) Red — write a failing test for a small piece of functionality; (2) Green — write the minimum code to make the test pass; (3) Refactor — improve code quality while keeping tests green. TDD in Agile context: (1) Supports Definition of Done — DoD often includes passing unit tests; TDD ensures tests exist; (2) Enables confident refactoring — comprehensive test suite makes Sprint-level refactoring safe; (3) Supports continuous integration — TDD's automated tests enable CI pipelines; (4) Enables sustainable pace — the 8th Agile principle; code with tests is faster to maintain long-term; (5) Living documentation — tests document what the code does. TDD reduces defects by 15-35% and development time by 15-35% (research by Nagappan et al.). Combined with BDD (Behavior-Driven Development) using Gherkin syntax (Given/When/Then), it creates tests readable by non-technical stakeholders.
Previous
What is pair programming and how does it relate to Agile?
Next
What are Agile metrics and how do you use them?