Test-Driven Development
A software development approach where tests are written before the code they validate, following a red-green-refactor cycle.
Also known as: TDD, Test-First Development
Category: Software Development
Tags: testing, software-engineering, methodologies, quality, agile
Explanation
Test-Driven Development (TDD) is a software development process where tests are written before the production code. The practice follows a 'Red-Green-Refactor' cycle: (1) Red - write a failing test for the desired functionality, (2) Green - write the minimum code to make the test pass, (3) Refactor - improve the code while keeping tests green. Benefits include: better design through testability constraints, living documentation, confidence in refactoring, fewer bugs reaching production, and faster debugging. TDD shifts thinking from 'how do I implement this?' to 'what should this do?' Critics note: initial slowdown, difficulty with UI and integration tests, and potential for brittle tests. TDD works best when combined with good testing practices, pair programming, and continuous integration. The approach was popularized by Kent Beck as part of Extreme Programming.
Related Concepts
← Back to all concepts