What is Test-Driven Development (TDD)?
TDD inverts the usual order: write a failing test first (red), write the minimum code to pass it (green), then clean up (refactor) — in minutes-long cycles. The tests accumulate into a safety net that makes future change cheap, which is the economic point: code you can change fearlessly stays alive.
Subtle but core: TDD is a design practice as much as a testing one — code written to be testable ends up modular by construction.
Worked example
Building a shipping-fee calculator, a developer writes the test first: "orders over $50 to zone 2 ship free." It fails (red) — the rule doesn't exist. She implements it (green), refactors the zone lookup, and moves to the next rule. Eight months later a new hire changes zone logic at 4pm on a Friday — and 130 green tests are why nobody minds.