Glossary termDevelopment practice

Test-Driven Development

Also known as: TDD, Test-first development

Software development practice in which a failing automated test is written before the code that makes it pass, after which the code is refined.

Test-driven development (TDD) reverses the usual order of writing code and tests. A developer first writes a small automated test describing a piece of behavior that does not yet exist and runs it to confirm that it fails. Next, they write just enough code to make the test pass. Finally they clean up the code, relying on the tests to catch any mistake. This loop, known as red, green, refactor after the colors test runners typically display, repeats in cycles of a few minutes, gradually building up both the program and a thorough suite of unit tests.

Kent Beck developed and popularized the practice in the late 1990s as part of Extreme Programming, an agile methodology, and described it in the book "Test-Driven Development: By Example" in the early 2000s. Beck has said he rediscovered rather than invented test-first programming, which appears in earlier sources. The approach relies on fast, automated test frameworks such as JUnit, which Beck created with Erich Gamma. Variants include behavior-driven development, which phrases tests as examples of desired behavior in language closer to that of users and business stakeholders.

Proponents argue that TDD produces simpler designs, since code is written to be testable from the start, along with a regression suite that makes later refactoring safe. Writing tests first also forces clarity about requirements before implementation. Critics counter that strict TDD can slow exploratory work, encourage over-reliance on mocks and produce tests tightly coupled to implementation details. Empirical studies of its effects on quality and productivity have produced mixed results. Many teams apply it selectively, writing tests first for tricky logic and bug fixes, and run them on every change through continuous integration.

Key points

  • TDD follows a short red, green, refactor cycle: write a failing test, make it pass, then clean up.
  • Kent Beck popularized the practice as part of Extreme Programming in the late 1990s.
  • Writing tests first forces clarity about requirements and produces a regression suite as a by-product.
  • Studies of TDD's effects on quality and productivity have reached mixed conclusions.

Related entries

Glossary term

Unit Testing

Programming

Practice of verifying that small, individual pieces of code, such as single functions or classes, behave correctly when tested in isolation.

Person

Kent Beck

Programming

American software engineer who created Extreme Programming, popularized test-driven development and co-wrote the Manifesto for Agile Software Development.

Glossary term

Refactoring

Programming

Process of restructuring existing code to improve its design, readability or maintainability without changing its external behavior.

Glossary term

Continuous Integration

DevOpsProgramming

Development practice in which programmers merge changes into a shared repository frequently, with each change verified by an automated build and tests.

Glossary term

Debugging

Programming

Process of finding, diagnosing and fixing defects in software or hardware that cause it to behave incorrectly or unexpectedly.

Glossary term

Code Review

Programming

Practice in which developers examine each other's source code changes to find defects, share knowledge and keep the codebase consistent.

Glossary term

Automated sequence of stages that builds, tests and releases software changes, combining continuous integration with continuous delivery or deployment.

Referenced by

Other entries that discuss or point to Test-Driven Development.