💳 Secure Payment

Full-Service Web & Software Agency · Klamath Falls and Redding

Behavior-driven development (BDD)

Work with Sean

Behavior-driven development turns a user story’s acceptance criteria into scenarios in plain language, and each scenario becomes a test the software must pass.

What BDD is

Behavior-driven development is an agile practice that puts developers, testers and the business around one table, talking about one thing: what the software should do, seen from the user’s side. Dan North (now Daniel Terhorst-North) developed it from 2003 and set it out in 2006, in “Introducing BDD”, starting from tests named as sentences about behavior.

Each behavior is written as a scenario in plain language, usually in Given-When-Then form, in the language called Gherkin. Here is one:

Feature: Cart

  Scenario: Adding a product to the cart
    Given "Widget A" is in stock at $25
    And the cart is empty
    When the customer adds "Widget A" to the cart
    Then the cart contains "Widget A"
    And the cart total is $25

Five steps, and two readers with different questions. The owner reads them and says whether that is what they asked for; a test checks them and says whether the software does it. That gives the owner and the webmasters one set of sentences to agree on before the software is built.

One scenario, two readers A highlighted box holds a scenario's three kinds of step: Given where things stand, When something happens, Then what must be true. Arrows lead to two readers: the owner reads it, agreed before code; a test checks it, done when it passes. Given where things standWhen something happensThen what must be truethe owner reads itagreed before codea test checks itdone when it passes
One scenario, outlined in violet, and its two readers. The owner reads the sentences and agrees them before any code is written; a test checks the same sentences, and the work is done when it passes.

Why it matters

  • User-centric: BDD has you think from the user’s perspective and ties every feature to a need someone named, so the owner can check the software against it.
  • Improved communication: A plain-language scenario is the one document the developer, the tester and the owner all read the same way.
  • Clear documentation: The scenarios double as documentation of what the software does, written so the next person can read it, and the test that checks each one carries its name.
  • Early detection of issues: A misunderstanding found while the scenario is still words costs a conversation; found after the code is written, it costs rework.

In the team’s work

On the Sean Dinwiddie’s Webmastery team, every custom feature is written as Gherkin scenarios before it is built. BDD helps you:

  • Say what your software should do, from the user’s side, before it is built.
  • Give your team one set of sentences to work from.
  • Keep a plain record of what your software does.
  • Check your software against the needs and expectations of your users, on every change.

BDD is less a tool than a habit: the behavior is agreed in plain words before any code is written, and the work is done when those words pass as tests. Module 2 teaches the habit.

Next steps

The next lesson introduces functional reactive programming (FRP), the functional ideas behind the application state those scenarios test. The lecture What Is a Function? starts those ideas at the pure function, the easiest code to test.

Copyright Sean Paul Payne Dinwiddie
All Rights Reserved