liveBook · Manning

Scenario outline

As explained in Effective Behavior-Driven Development

A Gherkin construct that defines a parameterized scenario expanded into multiple examples.

A scenario outline is a template for describing several similar scenarios compactly. Angle-bracket placeholders match column headings in an Examples table; each data row supplies values for a separate scenario. section 8.4.2

Consider an outline when it makes a repeated pattern easier to read:

  • Use a table when behavior naturally depends on variations in input data, such as acceptable or unacceptable contact details. section 8.4.3
  • Use one when several scenarios differ by just a few words and the outline makes those differences clearer. section 8.4.4
  • Prefer simple scenarios to start; compress them only when the resulting outline is easier to read. Remove redundant rows: large tables can repeat behavior and slow automation. section 8.4.3 section 8.4.4

An Examples table may include extra columns that help people understand why a row matters, even when the outline does not use their values. A description column is often placed first for readability. section 8.4.2

Listing 8.6 Scenario outline
Scenario Outline: Describe what remains of a pizza
  Given a diner cuts their pizza into <slices per pizza> slices
  When they eat <slices eaten> slices
  Then they should have <remainder> slices left

  Examples:
    | description       | slices per pizza | slices eaten | remainder |
    | Not hungry at all | 6                | 0            | all       |
    | Quite hungry      | 6                | 4            | 2         |
    | Very hungry       | 8                | 8            | none      |

A pizza example shows placeholders filled from three table rows, with a description column that adds context. section 8.4.2

Listing 8.10 Scenario outline emphasizes differences
Scenario Outline: Customer chooses to collect order
  Given the customer is <authenticated-or-not>
  When they choose to collect their order
  Then they should be asked to <action-needed> contact details

  Examples:
    | authenticated-or-not | action-needed |
    | authenticated        | confirm       |
    | unauthenticated      | supply        |

Compare authenticated and unauthenticated customers: the outline makes the two changing details visible in a compact table. section 8.4.4

How Effective Behavior-Driven Development covers it

How deep it goes
Explains templates, placeholder matching, row expansion, and unused columns without detailing automation internals.
Examples
Uses pizza calculations, contact-detail validation, and authenticated versus unauthenticated order collection.
What you can do after
Evaluate whether an outline clarifies repeated scenarios or whether separate scenarios are easier to read.
How it connects
Links Gherkin scenarios with Examples tables and data variations.

Also explained in

Compare how 2 books explain scenario outline →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.