Skip to content
BENIBIX Learn

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.

Development🧪 Testing & Quality

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.

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.
Full entry
Development🧪 Testing & Quality

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.

Example
Emma runs a shop, and Jack writes the code. They write the checkout rules together as Given, When, Then lines. Jack is done when every line passes.
Why it matters
The people who want the feature and the people who build it agree first. Then nobody codes the wrong thing.
Full entry

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.