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
# 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 oneEvery 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
| Practice | What it means |
|---|---|
| Discovery | the team and the customer work through stories using examples and find ambiguities before development |
| Formulation | the agreed examples are written as Gherkin scenarios, in business language and without code details |
| Automation | each 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 pagesVerified 9 Nov