Nguyen Le Phong

Behavior-Driven Development: Agree on Examples First, Automate Second

BDD started as a better way to talk about behavior.

The requirement sounded clear in planning: customers can cancel an order before it ships. Everyone nodded. Then QA asked what happens if the payment has already been captured. Product asked whether a partial shipment counts as shipped. An engineer asked whether the warehouse status is real time or synced every 15 minutes. One easy sentence had been hiding three different products.

Product, QA and engineering teammates lean over scenario cards and a laptop, working out what order cancellation should actually do.
BDD pays off at the moment a "simple" requirement gets specific enough for each role to see what the others assumed.

Behavior-Driven Development is built for that moment. Most people meet it as a testing tool with a funny syntax. It's more useful to treat it as a habit for conversations: before anyone writes code, the team agrees on concrete examples of how the system should behave, and only then decides which of those examples become automated tests.

Where it came from

Dan North described BDD in a 2006 post called Introducing BDD. He'd been teaching test-driven development and kept hitting the same confusion: where to start, what to test, what to call a test. He noticed that most of the misunderstandings came back to the word "test" itself. When he started saying "behaviour" instead, he wrote, "a whole category of coaching questions magically dissolved."

The bigger step came toward the end of 2004. North was explaining his behaviour-based vocabulary to business analyst Chris Matts, and Matts said, "But that's just like analysis." The two of them went on to write a template for a story's acceptance criteria: Given some initial context, When an event occurs, Then ensure some outcomes. Their first example was an ATM. Given the account is in credit, and the card is valid, and the dispenser contains cash, when the customer requests cash, then the account is debited, cash is dispensed and the card comes back.

Martin Fowler points out that Given-When-Then is a reformulation of the familiar test shape: setup, exercise, verify, which Bill Wake called Arrange, Act, Assert (GivenWhenThen). So the structure isn't new. What North and Matts added was a vocabulary that analysts, testers, developers and the business could all read.

Discovery comes first

The Cucumber team splits BDD into three practices, in this order: Discovery, Formulation and Automation. Their docs are blunt about the tests: documentation and automated tests are "nice side-effects," and "the real goal is valuable, working software" (Cucumber, Behaviour-Driven Development).

Discovery is where most of the value sits, and Matt Wynne's Example Mapping is the simplest way I know to run it. You need at least the "three amigos": a developer, a tester and a product person. Then four colors of cards:

  • Yellow: the story you're discussing.
  • Blue: each rule or acceptance criterion you already know.
  • Green: concrete examples, placed under the rule they illustrate.
  • Red: questions nobody in the room can answer yet.

Wynne suggests about 25 minutes for a well-understood, well-sized story, then a thumb vote on whether it's ready. The table itself tells you things. Lots of red cards mean you still have a lot to learn. Lots of blue cards mean the story is big and probably needs slicing. And he's clear that writing Gherkin during the session is generally a bad idea, because it pulls attention away from understanding the problem.

Here's what the cancellation story might look like after one round:

Rule (blue) Examples (green) Questions (red)
An order can be cancelled until it ships Paid, not shipped: cancelled, full refund started. Already shipped: customer sees "this order is on its way" and a link to returns. Does a partial shipment count as shipped?
Refunds go back to the original payment method Card payment: refund to the card. Store credit: credit restored right away. What if the card has expired since?
Only the buyer or support can cancel Buyer cancels from the app. Support cancels on the buyer's behalf, with a reason. Can a gift recipient cancel?

Three red cards after 20 minutes is a good result. You found them while they cost a message to the product owner, before they cost a hotfix.

Write scenarios in the language of the business

Formulation is where examples become scenarios. The test is whether someone outside engineering can read them. "Given row exists in orders table with status 3" fails that test. "Given the order has been paid and is waiting for shipment" passes.

Cucumber's guide on writing better Gherkin gives a handy check: "Will this wording need to change if the implementation does?" If yes, the step is describing implementation and should be rewritten (Writing better Gherkin). The guide prefers a declarative style (When "Bob" logs in) over an imperative one that spells out every visit, field and button click, because declarative scenarios read better as living documentation and survive UI changes.

A small team works with cards, a tablet and shared examples, rewriting technical workflow details in plain business language.
If only engineers can read a scenario, it has stopped doing its main job.

Don't stop at the happy path. Some of the most useful scenarios answer the awkward questions. What if the user lacks permission? What if the payment provider is down? What if two cancel requests arrive at the same moment? What should the customer see if the warehouse status flips while they're on the page? Those are the cases that otherwise show up first in production.

The words matter beyond the feature, too. When "cancelled," "refunded," "shipped" and "returned" mean the same thing in scenarios, code, tests and support docs, the product gets easier to reason about. When two teams use one word in two ways, a scenario review is where that tension shows up, and it shows up fast.

Automate at the right level

The trap is going straight to automation. A team adopts BDD and, within a month, has a big suite of end-to-end tests written in clumsy Gherkin. The feature files look readable. Every step hides slow browser setup and fragile selectors, and the team spends more time babysitting the suite than talking about behavior.

Pick the level for each scenario on purpose. A business rule like the refund method is usually best protected by a fast unit or integration test. A critical journey, like cancelling and seeing the refund confirmation, may deserve one end-to-end test. A rare manual operations path might only need a checklist. BDD never said every sentence has to drive a browser. If you're weighing the cost of test-first work in general, TDD: is it worth the time? looks at that trade-off, and the "-driven development" overview shows where BDD sits next to TDD and DDD.

Where BDD goes wrong

  • Every tiny change gets a formal workshop. A copy fix doesn't need three amigos.
  • Scenarios get written after the code, to tick a process box. At that point they document what you built, and the misunderstanding has already shipped.
  • The team writes dozens of examples without picking the few that settle a real decision. More examples don't make a story clearer. The right ones do.

A good session is small and practical. A PO, a tester, a developer and sometimes a designer sit around one behavior and ask: what example would prove we understand this? They write a few, cut the vague words, name the edge cases and leave with fewer open questions than they brought in. Some of those examples become automated tests later. The first output is a team that agrees.

Three teammates compare examples, notes and a whiteboard flow while deciding which behaviors are worth automating.
A good session ends with fewer vague words, named edge cases and a short list of what deserves a test.

Try this week

  • Pick the next story with any doubt in it and run a 25-minute example mapping session with a developer, a tester and the product owner.
  • Count the red cards. If there are more than a few, the story isn't ready, and that's useful to know now.
  • Take one existing scenario and ask Cucumber's question: would this wording change if the implementation did? Rewrite it if so.
  • For each new scenario, decide its test level (unit, integration, end-to-end or checklist) before anyone writes a step definition.

If your team often says "we all agreed" and then builds three different things, a handful of Given-When-Then examples is a cheap place to start listening to each other earlier. For rules with lots of conditions, a decision table drawn first makes the examples much easier to pick.

What did you think?

Frequently asked questions

What is Behavior-Driven Development?
A way of working where product, testing and engineering agree on concrete examples of how the system should behave before code is written. Dan North introduced it in 2006, and with Chris Matts he created the Given-When-Then template for acceptance criteria.
Is BDD the same as using Cucumber or Gherkin?
No. Cucumber's own docs split BDD into Discovery, Formulation and Automation, and call the automated tests a side effect. The goal is shared understanding and working software. Gherkin is one way to write the examples down.
What is example mapping?
A short session, about 25 minutes per story, where a developer, a tester and a product person sort the story into cards: yellow for the story, blue for rules, green for examples and red for open questions. Many red cards mean the story isn't ready yet.
Should every BDD scenario be an end-to-end test?
No. Choose the level per scenario. Business rules are usually best covered by fast unit or integration tests, a few critical journeys may deserve end-to-end tests, and rare manual paths might only need a checklist.