liveBook · Manning

Step

As explained in BDD in Action, Second Edition

A step is an individual Gherkin statement representing a precondition, action, or expected outcome in a scenario.

A money-transfer scenario is easier to discuss when it separates the starting balances, the transfer, and the resulting balances. Each of those statements is a step: one part of a Gherkin scenario that business stakeholders and developers can read together and potentially automate. section 2.3.5

Feature: Transferring money between accounts
  In order to manage my money more efficiently
  As a bank client
  I want to transfer funds between my accounts whenever I need to
  Scenario: Transferring money to a savings account
    Given Tess has a current account with $1000
    And a savings account with $2000.00
    When she transfers $500 from current to savings
    Then she should have $500 in her current account
    And she should have $2500 in her savings account
 
  Scenario: Transferring with insufficient funds
    Given Tess has a current account with $1000
    And a savings account with $2000.00
    When she transfers $1500 from current to savings
    Then she should receive an 'insufficient funds' error
    Then she should have $1000 in her current account
    And she should have $2000 in her Savings account

The transfer scenarios show Given steps establishing balances, a When step making the transfer, and Then steps checking the outcome. section 2.3.5

Use the keyword to show what a step contributes:

  • Given establishes a precondition and prepares the test environment. section 2.3.5
  • When states the action under test. section 2.3.5
  • Then states an expected outcome. section 2.3.5
  • And or But continues the preceding kind of step while making the scenario easier to read. section 7.2.4

Keep each step focused on one relevant condition or result. Splitting a combined assertion can make changes and failures easier to locate and steps easier to reuse. But more detail is not always better: hide routine setup and navigation when they distract from the business behavior being discussed. section 7.2.4 section 7.6.6

Scenario: Search for available hotels by distance
  Given Bindi needs to make a business trip to Paris
  And the following hotels have available rooms:
    | Hotel Name | Location | Distance from center |
    | Ritz       | Paris    | 3.2                  |
    | Savoy      | Paris    | 6.9                  |
    | Hilton     | Paris    | 12.5                 |
  When Bindi searches for a hotel within 10 km of Paris
  Then she should be presented with the following hotels:
    | Hotel Name | Location | Distance from center |
    | Ritz       | Paris    | 3.2                  |
    | Savoy      | Paris    | 6.9                  |

The hotel-search scenario keeps the available hotels as relevant setup and checks only the hotels within the requested distance, rather than spelling out login and page navigation. section 7.6.6

Steps can contain tables when test data or expected results are clearer in rows. A scenario outline can instead repeat the same steps with values supplied by an Examples table. Choose the form that makes the requirement clear at a glance. section 2.3.5

How BDD in Action, Second Edition covers it

How deep it goes
Defines the step keywords and works through focused wording and readable continuations, without detailing automation implementation.
Examples
Uses money transfers, bonus flight points, and hotel searches to contrast clear steps with combined or incidental detail.
What it assumes
Introduces the keywords from plain-English scenarios without requiring prior familiarity with Gherkin step notation.
What you can do after
Practice/perform writing focused Given–When–Then steps that preserve business meaning while leaving incidental setup out of the scenario.
How it connects
Connects Gherkin steps to scenarios, feature files, scenario outlines, example tables, and executable specifications.

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.