# Test-Driven Development (TDD)

> Write a test that fails first. Then write just enough code to pass.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** TDD, Test-First Development, Red Green Refactor

## Think of it like

Think of it like writing the quiz before you study. You know the goal before you start.

## Definition

Test-driven development means you write a test before the code it checks. First you write a test and watch it fail, because the code does not exist yet. Then you write just enough code to make it pass. Then you tidy the code while the test stays green. This loop is called red, green, refactor, and Kent Beck made it popular around 2000.

## Example

Emma needs a function that rounds prices. She writes a test that 2.345 becomes 2.35, sees it fail, then writes the function until it passes.

## Why it matters

Every line of code comes with a test. You also think about how code is used before you write it.

## Common mistake

Skipping the step where the test fails. A test you never saw fail might not be testing anything.

## Three principles

- **Red.** Write a test that fails.
- **Green.** Write code until it passes.
- **Refactor.** Tidy, keep it green.

## Related terms

- [Unit Test](https://learn.benibix.com/term/development/unit-test)
- [Refactoring](https://learn.benibix.com/term/development/refactoring)
- [Test Case](https://learn.benibix.com/term/development/test-case)
- [Test Coverage](https://learn.benibix.com/term/development/test-coverage)
- [Behavior-Driven Development (BDD)](https://learn.benibix.com/term/development/behavior-driven-development)

## Told apart from

- [TDD vs BDD](https://learn.benibix.com/compare/test-driven-development-vs-behavior-driven-development): Test-driven development starts with a failing test in code, then the code that makes it pass. Behavior-driven development starts one step before that. The team writes plain Given, When, Then lines first, and those lines run as tests too.

---

Source: https://learn.benibix.com/term/development/test-driven-development
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
