liveBook · Manning

Scenario keyword

As explained in BDD in Action, Second Edition

The Scenario (or Example) keyword is a Cucumber syntax keyword that introduces an executable behavior scenario.

A concrete example can reveal what a broad requirement leaves unsaid. The `Scenario` keyword gives that example a name and introduces it as a structured description of expected behavior. The steps that follow usually state the context with `Given`, an action with `When`, and the expected outcome with `Then`. section 3.4 section 2.3.4

Choosing a train

Scenario: Display the next train going to the requested destination Given the next train leaves Hornsby at 8:02 When a traveler wants to go from Hornsby to Chatswood at 8:00 Then they should be told to take the 8:02 train The title identifies the behavior being illustrated. The steps make one specific case discussable: the departure time, the request, and the answer can all be checked with stakeholders. section 3.4

A scenario is more than a test-shaped sentence. Teams first explore examples and counterexamples together to uncover assumptions; they then formalize useful cases as scenarios. These business-readable specifications can become automated acceptance tests and living documentation. Keep enough detail to make the outcome clear without burying the behavior the team needs to agree on. section 3.3.1 section 7.0

How BDD in Action, Second Edition covers it

How deep it goes
Shows named scenarios with Given–When–Then steps and discusses their purpose, while leaving automation mechanics to a later treatment.
Examples
Uses a named train-departure scenario and a funds-transfer scenario to show concrete starting conditions, actions, and outcomes.
What it assumes
Starts with stakeholder examples of desired behavior and introduces the structured scenario notation before discussing automation.
What you can do after
Practice/perform writing named behavior scenarios that clarify expected outcomes and can serve as automated acceptance criteria.
How it connects
Connects scenarios to Gherkin, Given–When–Then notation, acceptance criteria, Cucumber, and living documentation.

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.