Test-Driven Development
An engineering discipline of writing a failing test before the code that makes it pass — producing better-designed, better-tested software at a sustainable pace.
Definition
Test-Driven Development (TDD) is the practice of writing an automated test that fails, then writing the minimum production code that makes it pass, then refactoring both the test and the production code while keeping all tests green. The cycle — red, green, refactor — repeats many times per hour. TDD is a design discipline as much as a testing discipline: the act of writing the test first forces clear thinking about the interface and behaviour of the code.
Why It Matters
TDD-developed code is, on average, better designed, better tested, and easier to change. Empirical studies vary in their estimates, but the consistent finding is significant defect reduction (20–60%) at a modest cost in development time (15–30%) and a substantial reduction in long-run maintenance cost.
The Cycle
- Red. Write a small, failing test that expresses the next required behaviour.
- Green. Write the smallest production change that makes the test pass.
- Refactor. Improve the design with all tests still passing.
Real-World IT Example
A trading-engine team adopted TDD strictly after a production incident traced to an under-tested edge case. Over twelve months, production incidents in the affected module dropped from 14 to 2, code coverage rose from 38% to 91%, and feature throughput — initially slower for the first two months — recovered and then exceeded the pre-TDD rate. The team attributed the speed gain not to coverage alone but to confidence: changes were made without fear, and reviews moved faster.
Real-World Construction Analogue
The construction equivalent is the discipline of "design for testability" in commissioning. On a $620M LRT depot, the systems integrator specified test points, sensors, and simulation interfaces during design — not after construction. Every subsystem could be tested in isolation before integration. The cost was 1.4% of design fee; the saving in commissioning rework was an estimated 8–11% of commissioning cost.
Common Mistakes
- Writing tests after code and calling it TDD. This loses the design benefit.
- Writing too-large a test. Tests should be small and focused.
- Skipping the refactor step. Without it, code quality decays.
- TDD as religion. Some code (exploratory spikes, UI prototypes) is poorly served by strict TDD.
- Testing implementation, not behaviour. Such tests break on every refactor.
Expert Tips
- Pair TDD with pair programming — particularly ping-pong style.
- Tests should describe behaviour in domain language; reviewers should understand them without reading the production code.
- Use TDD where the design is uncertain; it surfaces design issues fast.
- Resist mocking infrastructure; integration tests have a place.
- Measure test execution time; slow tests undermine the cycle.
Practical Lessons Learned
- The first month of TDD adoption is slow. Most teams that abandon it abandon during that month.
- TDD is most valuable on code that will be changed many times; least valuable on throwaway code.
- The discipline survives only with engineering leadership that protects it during deadline pressure.
Key Takeaways
- TDD writes the failing test first, then the production code, then refactors.
- It is a design discipline as much as a testing one.
- Expect a slow first month and a sustained-velocity gain thereafter.
- Pair with refactoring and pair programming for maximum benefit.
- The same "design for testability" thinking applies to commissioning in physical systems.
Related Encyclopedia Entries
Related Research Articles, Case Studies & Tools
Frequently Asked Questions
Is TDD slower than writing tests later?
Initially 15–30% slower; over the medium term, faster due to fewer defects and easier change.Does TDD replace QA?
No. It produces better code earlier; QA still validates the system at higher levels.Should I use TDD for UI code?
Selectively. Behaviour-level tests work well; pixel-level rarely do.Can TDD be done in any language?
Yes, but ecosystems vary in tooling quality. Strong test-runner support helps adoption.Does TDD work for legacy code?
Yes — the related discipline is 'characterisation testing' to capture current behaviour before changing it.How do I introduce TDD to a sceptical team?
Start with a single complex module, pair with a champion, measure outcomes, share results.What is the biggest cause of TDD failure?
Abandoning the practice during deadline pressure. Engineering leadership must protect the discipline.What is a common misconception about Test-Driven Development?
That the topic is well-defined across all references. In practice, definitions vary between PMBOK, PRINCE2, AACE and ISO 21500 — this entry uses the definition most aligned with field practice on capital projects, and flags where the standards diverge.Which related encyclopedia entries should I read alongside Test-Driven Development?
Read Earned Value Management, Critical Path Method and the DCMA 14-point assessment next. The full A–Z is available in the PMMilestone Encyclopedia, and quick one-line definitions live in the PM Glossary on the flagship platform.How does Dr. Hassan Eliwa's research treat Test-Driven Development?
Dr. Hassan Eliwa's research focuses on owner-side project controls, schedule integrity and forensic delay analysis on capital construction and power programmes. Test-Driven Development is treated through that lens — what a planning or controls engineer is expected to do with it on a live project, not its textbook definition alone. See the full research library at PMMilestone Research Articles.How is Test-Driven Development defined on PMMilestone Research & Insights?
An engineering discipline of writing a failing test before the code that makes it pass — producing better-designed, better-tested software at a sustainable pace. For the full treatment, see the definition, principles, applications and related entries above — every encyclopedia entry follows the same research-grade structure.
People also ask
Follow-up questions practitioners search for next — each one points to the calculator, template or reference entry that answers it.
Where is this in the glossary?
Quick-lookup definitions across 1,200+ PM terms. PM Glossary on PMMilestone.org ↗
Which learning track covers this end-to-end?
Structured tracks from beginner planner to programme controls director. Project Controls Academy ↗
Which book goes deeper than this entry?
Practitioner field handbooks with worked numerical examples. Books & Publications ↗
Which calculator on PMMilestone.org applies here?
The integrated EVM workbook covers most cost-schedule diagnostics. EVM Calculator ↗
Related Entries
Further reading on PMMilestone.org
Curated companion resources hosted on the flagship platform, PMMilestone.org.
- For practitioners who want to go deeper, the Learning Tracks.
- Engineers researching this topic typically continue with the Books & Publications.
- A practical companion to this entry is the EVM Calculator.
- Closely related on the flagship platform is the Schedule Health Checker.
- Useful alongside this article is the PMMilestone.org knowledge hub.