liveBook · Manning

When

As explained in Effective Behavior-Driven Development

A Gherkin step keyword that introduces the stimulus or event causing the behavior under specification.

A When step names the stimulus or event that causes the behavior being specified. The tricky part is deciding which action triggers the outcome and which belongs in the scenario’s context. section 8.6

To choose the When step:

  • Identify the action that directly leads to the expected outcome; move other relevant conditions into the Given context. section 8.3.5
  • Usually use one When per scenario. Use more only when multiple triggering actions must happen simultaneously. section 8.3.5
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

Here, the customer’s unauthenticated state and choice of collection form the context; providing unacceptable contact details triggers the refusal. section 8.3.5

How Effective Behavior-Driven Development covers it

How deep it goes
Defines the trigger and explains how to distinguish it from context, including the usual single-trigger constraint.
Examples
Contrasts choosing order collection with providing unacceptable contact details as alternative triggers for a refusal.
What you can do after
Evaluate scenario steps by distinguishing the triggering action from conditions that belong in context.
How it connects
Connects Given, When, and Then to context, action, and expected outcome, respectively.

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.