liveBook · Manning

Given/When/Then format

As explained in BDD in Action, Second Edition

Given-When-Then notation is a structured scenario format for expressing preconditions, an action or event, and the expected outcome.

A requirement such as “show the next train” can hide important questions: which line, which direction, and how many departures? Given/When/Then turns a concrete example into a scenario that stakeholders, testers, and developers can examine together. Writing it often exposes assumptions before implementation begins. section 3.4 section 2.3.4

A scenario separates three concerns:

Transfer between accounts

Given a client has $1,000 in a current account and $2,000 in savings; When she transfers $500 from current to savings; Then the balances are $500 and $2,500 respectively. The amounts make the expected behavior discussable and checkable. section 2.3.4

Include preconditions that affect the business result, but avoid burying the goal in setup detail. For a booking change with no additional charge, Frequent Flyer membership may matter; a login step may not explain that rule. Extend a clause with And or But when needed, and split distinct conditions or outcomes into focused steps. section 7.2.3 section 7.2.4

Feature: Earning Frequent Flyer points from flights
 
        Scenario: Flights within Europe earn 100 points
          Given Tara is a Frequent Flyer traveler
          When she completes a flight between Paris and Berlin
          Then she should earn 100 points

This complete scenario makes a points rule concrete: traveler status supplies the context, completing a flight is the event, and earning 100 points is the expected result. section 7.1

Keep scenarios readable as living documentation, not merely as test scripts. Tables can reduce repetition or present test data and results. BDD tools such as Cucumber and SpecFlow can execute structured scenarios as acceptance tests and produce reports in business-facing terms. section 7.0 section 7.1

How BDD in Action, Second Edition covers it

How deep it goes
Explains each clause, relevant preconditions, and focused extensions; defers automation and implementation.
Examples
Uses account transfers, revised train departures, flight points, and booking changes to make scenarios concrete.
What it assumes
Builds on concrete feature examples and acceptance criteria while explaining the three-part scenario structure from its basics.
What you can do after
Practice/perform writing concise, business-readable scenarios that can become executable acceptance tests.
How it connects
Connects BDD scenarios with acceptance criteria, executable specifications, feature files, tables, and living documentation.

Also explained in

Compare how 2 books explain Given/When/Then format →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of BDD in Action, Second Edition. The section links point to the parts of the book it draws on.