TDD vs BDD
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.
Test-Driven Development (TDD)
Write a test that fails first. Then write just enough code to pass.
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.
Behavior-Driven Development (BDD)
Writing features as Given, When, Then lines. The lines also run as tests.
Behavior-driven development is a way to describe a feature in plain sentences before coding it. Each example is written as Given, When and Then. Given sets the scene, When is the action, and Then is the result. Tools like Cucumber turn these sentences into tests that run. People who do not code can read and agree on them.
In one line
- Test-Driven Development (TDD)
- Write a test that fails first. Then write just enough code to pass.
- Behavior-Driven Development (BDD)
- Writing features as Given, When, Then lines. The lines also run as tests.