liveBook · Manning

Shareable scenario context pattern

As explained in Effective Behavior-Driven Development

A scenario-execution pattern for sharing information between steps during a scenario.

When a later step needs information established by an earlier step in a different class, a shareable scenario context lets both steps access it. The shared information belongs to that scenario’s execution, so it cannot affect another scenario’s outcome. section 13.2 section 13.5

An authenticated customer places an order

An authentication step records Rebecca’s name in an AuthenticationContext. An ordering step can then use the authenticated customer to place an order, and subsequent steps can refer to that customer without repeating the name. section 13.2

Choose what to share with care:

  • Share context across classes when a step depends on information introduced earlier elsewhere in the scenario. section 13.2
  • Keep data in a separate context class only when multiple glue-code classes need it; a single-class use does not yet require that move. section 13.2
  • Consider storing a derived object instead of an identifier to avoid a later lookup, while weighing the risk of stale data if another service changes the object. section 13.2

How Effective Behavior-Driven Development covers it

How deep it goes
Explains applicability, scenario isolation, and a data-storage trade-off, with a concrete cross-class implementation example.
Examples
Uses authenticated customer details shared between authentication and ordering steps in an order-cancellation scenario.
What it assumes
Assumes steps may depend on information introduced earlier in the same scenario, including by a step defined in another class.
What you can do after
Apply the pattern to let steps in separate classes share scenario information without affecting other scenario executions.
How it connects
Connects to Local Scenario Context, step definitions, and scenario execution context.

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.