liveBook · Manning

Context

As explained in Effective Behavior-Driven Development

The state or conditions established before an action takes place in an example.

Context is the state of the system before the behavior being illustrated. In an example, it works with an action that triggers the behavior and an outcome that describes the resulting state. section 3.7

Keep context useful and focused:

  • Include only concrete details needed to understand the rule; leave unrelated data, such as the pizza type when illustrating an address change, to examples about those behaviors. section 3.2
  • When context and action seem ambiguous, ask which event directly triggers the outcome. The answer can depend on how the business works. section 8.3.5
  • In Gherkin, Given steps establish context before a When step states the triggering event. section 8.3.2
Listing 8.4 Single action (contact details)
Given the customer is unauthenticated
And they chose to collect their order
When they provide contact details unacceptable for customer-collection 
Then they should be prevented from progressing

This scenario treats unauthenticated status and the customer’s choice to collect as context, leaving unacceptable contact details as the triggering action. section 8.3.5

How Effective Behavior-Driven Development covers it

How deep it goes
Defines context and explains its boundary with action, noting that classification can vary with business behavior.
Examples
Uses a pizza delivery-address change and an unauthenticated customer choosing collection with unacceptable contact details.
What you can do after
Apply Gherkin’s Given step to express relevant preconditions and distinguish them from the triggering action.
How it connects
Connects context with action, outcome, examples, rules, and Gherkin’s Given, When, and Then steps.

Also explained in

Compare how 30 books explain 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.