Behaviour-driven development (BDD) explained by example

Kong To
13 min readOct 31, 2019

Fundamentals of BDD with three steps : discovery, formulate, automation.

With this article, I’ll walk through the behaviour-driven development methodology.

BDD & 3 amigos

Let’s jump straight in with an example of a behavioural test for a cash machine.

A Scenario Example

The first thing to notice is that the test is written in plain English.

The second thing to notice is the test is made of three different sections:

  • Given : it’s the arrangement of context state — the starting state
  • When : it’s the event, a trigger or when a user does something
  • Then : it’s the outcome with the expected results

Once scenarios are ready, the development team can begin their work. Each of the tests will be running — and in the absence of any code — they would fail. The developers start writing code. As more code is written the tests will begin to turn from red to green. When they are all green, the job is done.

What is BDD ?

--

--

Kong To

Architect, code crafter. Code quality matters. Technical writer @TheFork, a Tripadvisor company