Operations · Operations & process management

Behavior-driven development (BDD)

1SPECIFY2TEST3DEVELOP

Use it when

Product people, developers and testers keep disagreeing about what a feature should do, and you want agreed examples that also run as automated tests.

Skip it when

  • Only developers need to agree the behavior of single classes or functions. Use Test-driven development (TDD), which this builds on.
  • The work is not yet broken into small user stories. Write them with User story framework first.
  • Nobody on the team can say what the right outcome is for most cases. Get the answers from users or a short spike before you hold a session.

What to apply first and what to use instead are listed below.

Inputs

  • Upcoming user story
    One small change with any acceptance criteria already known, from the top of the backlog, due in the next iteration.
  • Three amigos
    At least a product person, a developer and a tester, plus anyone who can answer the story's questions, for a session of about 25 minutes.
  • Cards or a shared board
    Four colors for the story, its rules, its examples and open questions.
  • Scenario runner
    A tool set up in the project that runs given, when, then scenarios against the system, such as Cucumber.
  • Domain termsOptional
    The business's own words for the things in the story, from earlier scenarios or a glossary.

Steps

  1. Hold a discovery session on one story, writing each rule on its own card, concrete examples under each rule, and questions nobody present can answer on separate cards.
  2. Decide at the end of the session whether the story is ready, should be split, or needs its questions answered first.
  3. Write each agreed example as a scenario in given, when, then form using the business's terms, and have the product person review the wording.
  4. Connect each scenario's steps to the system as an automated test, run it, and watch it fail.
  5. Build the behavior, using test-first cycles for the internal parts, until the scenario passes.
  6. Keep the passing scenarios in the suite as living documentation, and rewrite or delete a scenario when its business rule changes.

Output

A feature file of agreed scenarios for the story, all passing in the automated suite, with a list of deferred stories and open questions.

  • Story
  • Rules
  • Scenario for each example (given, when, then)
  • Automation status (failing or passing)
  • Open questions with owner
  • Stories split off and deferred

Done when

  • Every rule has at least one example, or a note that the group agreed none was needed.
  • Every open question has an owner, and is answered or agreed as minor before the story enters development.
  • Every scenario describes one event in the business's own terms.
  • The product person has reviewed the wording of every scenario.
  • Every scenario runs in the automated suite and passes.

Measure

For three to six iterations after you start, track rework on stories after review, defects found after release, and stories sent back for clarification during development. Compare each with the same measures from the iterations before you started. It worked when all three fall, and the suite catches regressions before release.

Hypothetical example

A team at Ferro Bank took the story "As a cardholder, I want to freeze my card so that no one can use it if I lose it." In a 25-minute session they wrote three rules. A frozen card declines new payments, a frozen card still accepts refunds, and only the cardholder can unfreeze it. Each rule got one or two examples, such as the one where a refund arrives on a frozen card. One question card asked whether subscriptions should still be charged, and the product owner took it away. The developer and tester wrote five scenarios in the bank's terms, the product owner approved them, and all five ran red, then green, before the story closed.

Common mistakes

  • Typing formal scenarios into a tool during the discovery session. Capture rough examples on cards first and write the scenarios afterwards.
  • Writing scenarios in technical terms only developers use. Use the business's words so the product person can check them.
  • Letting the group argue over an outcome nobody knows. Write it on a question card with an owner and move on.
  • Pulling a story covered in rule cards into development. Split it and defer the less important part.
  • Keeping a failing scenario whose premise has changed. Rewrite or delete it when the business rule has changed.

Sources

By company stage

  1. Pre-IdeaNot applicableThere is no software being built.
  2. IdeaUsefulShared behavior specs help a small team build an MVP that customers want, though not required.
  3. Early StartupUsefulClear specs reduce rework while the product changes with early traction.
  4. StartupUsefulMore engineers and teams benefit from shared behavior definitions that serve as tests.
  5. GrowthUsefulHelps keep quality and alignment across departments as the product grows.
  6. ScaleUsefulUseful across several products, but teams already have testing practices.
  7. EnterpriseUsefulUseful in some units, but not a defining practice at this size.

Apply first

  • Test-driven development (TDD)Operations · Operations & process management

    BDD grew out of TDD, adding business-readable given-when-then specifications to the test-first cycle; the red-green-refactor practice comes first.

Use instead

  • Test-driven development (TDD)

    Only developers need to agree the behavior of single classes or functions. Use Test-driven development (TDD), which this builds on.

  • User story framework

    The work is not yet broken into small user stories. Write them with User story framework first.

Recommended resources

No sponsored resources on this framework yet. Sponsored listings would be labelled here, never in search.

Progress is not saved until you have an account. Create a free account