Skip to content
PMPCAPM

Test-Driven Development (TDD)

Test-Driven Development (TDD) is a software development practice where developers write a failing test before writing the production code that makes it pass, following a red-green-refactor cycle.

Explanation

TDD follows a simple three-step cycle: Red (write a failing test), Green (write the minimum code to make the test pass), and Refactor (improve the code while keeping tests passing). This cycle is repeated for each small piece of functionality, resulting in comprehensive test coverage and well-designed code.

By writing tests first, developers clarify the expected behavior before writing code, which leads to better design decisions. TDD produces a suite of automated tests that serve as both documentation and a safety net for future changes. When requirements change, the test suite quickly reveals if changes break existing functionality.

TDD is one of the core XP practices but has been widely adopted beyond XP. It requires discipline and practice to master but pays significant dividends in code quality, design, and maintainability. For the exam, know TDD as a development practice that improves quality through test-first development.

Key Points

  • Red-Green-Refactor cycle: fail, pass, improve
  • Tests are written before the production code
  • Results in comprehensive automated test coverage
  • Improves code design and provides a safety net for changes

Exam Tip

TDD means writing the test BEFORE the code, not after. The key sequence is: write failing test, write code to pass, then refactor.

Frequently Asked Questions

Related Topics

Test your knowledge

Practice scenario-based questions on this topic with detailed explanations.