Web apps & software

What is test-driven development (TDD)?

Test-driven development, or TDD, is a way of programming in which you write a small automated test before the code that satisfies it, watch it fail, make it pass with the simplest code, and then clean up.

The red-green-refactor loop

Red: write a test for behavior that does not exist yet, such as "a cancelled booking within five minutes costs nothing," and see it fail. Green: write just enough code to pass. Refactor: improve names and structure while the test keeps you safe. Repeat in short cycles of minutes.

Benefits

Code ends up testable by design, requirements get clarified before coding, and the suite grows alongside the product. Many developers find it reduces debugging time.

Honest limits

TDD suits business rules, calculations and APIs well. It is awkward for exploratory work, visual design and code that mostly wires libraries together. Bad tests locked to implementation details can slow change down. Some teams apply it selectively, and that is a reasonable position.

Asking a vendor

If a team claims to practice TDD, ask to see the tests in the repository history committed alongside the features.

Questions, answered

Writing is slower at first, but fewer defects and less rework often offset it on long-lived products.

No. BDD describes behavior in business language, and often builds on TDD ideas.

By the Stegnor team · Updated