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
Extreme Programming (XP)
Extreme Programming (XP) is an agile software development framework that emphasizes technical excellence and engineering practices such as pair programming, test-driven development, continuous integration, and frequent releases.
Continuous Integration
Continuous Integration (CI) is the practice of frequently merging code changes into a shared repository, where automated builds and tests verify each integration to detect problems early.
Refactoring
Refactoring is the practice of restructuring existing code without changing its external behavior to improve its readability, reduce complexity, and make it easier to maintain.
Definition of Done
The Definition of Done (DoD) is a formal description of the state of the Increment when it meets the quality measures required for the product, providing a shared understanding of what it means for work to be complete.
Most-studied PMP concepts
High-yield topics our learners drill most before exam day.
Burndown Chart
A Burndown Chart is a graphical representation of work remaining versus time in a Sprint or release, showing whether the team is on track to complete the planned work.
Relative Estimation
Relative Estimation is an agile technique where work items are sized in comparison to each other rather than in absolute units like hours or days, providing faster and more accurate estimates.
Sprint Review
The Sprint Review is a Scrum event held at the end of the Sprint where the Scrum Team presents the Increment to stakeholders, gathers feedback, and collaborates on what to do next.
Sprint Backlog
The Sprint Backlog is the set of Product Backlog items selected for the Sprint, plus the Sprint Goal and the plan for delivering the Increment.
Timeboxing
Timeboxing is the practice of allocating a fixed, maximum amount of time for an activity, after which the activity stops regardless of whether it is complete.
Resource Leveling
Resource leveling is a resource optimization technique in which adjustments are made to the project schedule to keep resource usage at or below a defined limit, often resulting in a longer project duration.
Risk Register
The risk register is a project document that records the details of individual project risks, including their identification, analysis results, response plans, and current status.
Stakeholder Mapping
Stakeholder mapping is the visual representation of stakeholder relationships, influence, interest, or other attributes using grids, matrices, or diagrams to support analysis and engagement planning.
Cost Performance Index (CPI)
Cost Performance Index (CPI) is an EVM efficiency metric that measures cost performance as the ratio of earned value to actual cost: CPI = EV / AC.
Part of
Agile & Hybrid
Test your knowledge
Practice scenario-based questions on this topic with detailed explanations.