Test-Driven Development
A practice where tests are created before the implementation begins, so work is checked continuously as it progresses and teams strive for zero defects.
Key Points
- Write a test first, see it fail, implement the minimum code to pass, then refactor (red-green-refactor).
- Tests act as executable requirements that guide design and clarify scope.
- Encourages small, incremental changes with fast feedback and fewer defects.
- Works best with automated unit tests and continuous integration for rapid validation.
Example
On a payments feature, the team writes unit tests for handling invalid cards and approving valid transactions before any code exists. The tests fail at first. Developers then add only the logic needed to make the tests pass, run the suite in the CI pipeline, and refactor the code while keeping all tests green.
PMP Example Question
Which practice requires creating automated tests before writing the production code, ensuring continuous validation and minimal defects during development?
- Continuous Integration
- Test-Driven Development
- Code Reviews
- Kanban WIP Limits
Correct Answer: B - writing tests before coding (Test-Driven Development)
Explanation: TDD mandates writing failing tests first, then adding only enough code to pass them, which provides constant feedback and lowers defect rates.
HKSM