What and Why

Test-Driven Development (TDD) and Behavior-Driven Development (BDD) are practices that flip the normal order of writing code. Instead of writing code then tests, you write tests (or specifications) first.

You'll encounter TDD and BDD as either mandates from tech leads or as personal techniques engineers pick up after they've been burned enough times by untestable code. They're related but distinct: TDD is a coding discipline; BDD is a collaboration and specification technique.


Core Concepts

Why would you write a test before the code exists?

It sounds backwards. You can't test code that doesn't exist.

That's the point. Writing the test first forces you to think about the interface before the implementation. You have to decide:

  • What should this function be called?
  • What arguments does it take?
  • What does it return?
  • What happens when it fails?

When you write code first, you answer these questions in the implementation —…

In the full tutorial

  • How It Works in Practice
  • Common Mistakes
  • Tradeoffs
  • Quick Reference

Glossary history

Click dotted jargon to save explanations here.