Back to Glossary
Testing

TDD (Test-Driven Development)

A software development practice where tests are written before the actual code, following a cycle of: write a failing test, write minimal code to pass, then refactor.

Definition

TDD follows the "Red-Green-Refactor" cycle: Red (write a test that fails), Green (write the minimum code to pass the test), Refactor (improve code while keeping tests green). This approach ensures every feature has test coverage, encourages simpler designs, and provides immediate feedback. TDD was popularized by Kent Beck as part of Extreme Programming (XP).

Why It Matters

Teams practicing TDD report 40-90% reduction in bug density. TDD creates a comprehensive test suite as a byproduct of development, documents expected behavior, and enables confident refactoring. Studies show TDD code has fewer defects and better design.

Example

Before writing a password validator, a developer writes a test: expect(validatePassword("abc")).toBe(false). The test fails. They implement the minimum validation logic to pass, then refactor for clarity.

Related Terms

TDDtest-driven developmentwhat is TDDTDD meaningtest first

Automate Code Review with diffray

Multi-agent AI system for code review. Automatically finds bugs, security vulnerabilities, and architecture issues.