Bookmarks

BDD — behaviour-driven development

Behavior-Driven Development

An approach to development in which requirements are described as examples of system behaviour in language the business understands, and those examples are then automated as tests.

Also: BDD, behavior-driven development, behaviour-driven design

checked 9 Nov

All terms

BDD grew out of TDD. Dan North developed the approach from late 2003 and described it in a 2006 article, aiming to shift the focus from the word “test” to the word “behaviour”: first agree how the system should behave, and only then write code. Requirements are written as scenarios in Gherkin, a language close to plain text, so analysts, testers and customers can all read them.

What a scenario looks like

gherkina Gherkin scenario
# language: enFeature: Password recovery  Scenario: the reset link has expired    Given the user is registered    When they open the email with the reset link after 60 minutes    Then the link does not work and they are offered a new one

Every scenario follows the Given-When-Then template: an initial state, an action and an expected result. Scenarios add up to living documentation: it always describes the system’s current behaviour, because it fails together with any code that no longer matches it.

Three practices

PracticeWhat it means
Discoverythe team and the customer work through stories using examples and find ambiguities before development
Formulationthe agreed examples are written as Gherkin scenarios, in business language and without code details
Automationeach step of a scenario is bound to test code and runs in CI like any other test

A scenario step checks nothing by itself. A framework (Cucumber for Ruby, Java and JavaScript, Reqnroll for .NET, behave for Python) looks up a step definition with a matching pattern for each step line and passes it the parameters from the text.

BDD and TDD

TDD drives development at the code level: the red-green-refactor cycle with unit tests shapes the design of classes and functions. BDD lifts the same cycle one level up: its starting material is not a method call but the behaviour of the system as the user sees it. The two approaches do not compete: BDD scenarios are often automated on top of code written with TDD, with ordinary unit tests underneath.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • TDDtest-driven development

    TDD writes tests before code at the unit level; BDD lifts the cycle to the level of requirements, with examples of system behaviour.

  • acceptance criteria

    Acceptance criteria list the conditions for accepting a story; in BDD they are written as Gherkin scenarios and automated.

  • UATuser acceptance testing

    UAT checks the finished system by hand before acceptance; BDD describes the expected behaviour in scenarios before development starts.

In depth in the references

where the topic is covered in detail