What, not how
In short: A scenario says what the system does, not how you click around the screen. "Click the Order button" breaks with every design change while the rule stays the same. One scenario checks one behaviour: one "When". The words are the business words: cart, order, delivery, not tables and URLs.
Problem
Forty scenarios and one button
The shop changes the design of the cart. The "Order" button becomes "Go to payment" and moves to a new line. Nothing in the rules has changed.
The next morning 40 scenarios fail. They are all about delivery, and they all start like this:
Feature: Free delivery
Scenario: Delivery under the boundary Given I open the shop website And I put a mug for 49.99 € in the cart And I open the cart When I click the "Order" button Then the bottom of the screen says "Delivery: 4.90 €"The owner cannot read them either. They look for the delivery rule and see buttons.
The idea
What, not how
This scenario says how to click around the screen. That is why it is called imperative: a series of commands. The same example, told as what the system does, is declarative:
Feature: Free delivery
Scenario: An order just under the boundary Given a cart of 49.99 € When I place the order Then delivery is 4.90 €Three lines instead of five, and none of them knows about buttons. If tomorrow the order is placed by voice or through the mobile app, the scenario stays the same. The rule has not changed, so the scenario should not change either.
The "how" does not disappear. It moves into the code that binds the step "When I place the order" to the system. One line there gets fixed for the new button, not 40 scenarios.
Try it
What or how?
Exercise
Rewrite it
1. Without the buttons. The editor holds the scenario from the start of the lesson.
Rewrite the scenario in the language of the vocabulary: no website, buttons or screen. Add an example exactly on the boundary too, so that both bugs are caught.
Solution
Feature: Free delivery
Scenario: An order just under the boundary
Given a cart of 49.99 €
When I place the order
Then delivery is 4.90 €
Scenario: An order exactly on the boundary
Given a cart of 50.00 €
When I place the order
Then delivery is free
The steps about buttons and screens are not in the vocabulary, so they cannot run. The vocabulary is the language the business and the team share: cart, order, delivery. Each of the two scenarios catches one bug: the boundary at 50.00 € and the fee at 49.99 €.
The idea
One behaviour per scenario
Here is something else that looks thrifty:
Feature: Free delivery
Scenario: Delivery Given a cart of 49.99 € When I place the order Then delivery is 4.90 € Given a cart of 50.00 € When I place the order Then delivery is freeThese are two scenarios in one. If it fails, you have to read the lines to find out which behaviour is broken. And if the first half fails, the second half does not even run.
The rule is one behaviour per scenario: one "When", and the name states that behaviour. If you need an "and" in the name ("cancelling and refunding"), there are two behaviours.
Exercise
Split it
2. Two in one. In this task two "When" steps in one scenario are an error.
Split the scenario in two: each with one behaviour and a name that states it.
Solution
Feature: Free delivery
Scenario: Under 50 € delivery is paid
Given a cart of 49.99 €
When I place the order
Then delivery is 4.90 €
Scenario: From 50 € delivery is free
Given a cart of 50.00 €
When I place the order
Then delivery is free
Now each scenario has a name that reads like a rule: "Under 50 € delivery is paid", "From 50 € delivery is free". When one fails, the name says what is broken without reading the steps.
The idea
The language of the business
The words in a scenario are the words of the owner and the customer: cart, order, delivery, promo code. The same as in the story and on the Example Mapping board. If the business says "order", the scenario does not say "request", and the code does not say cart_submission.
We do not write:
- names of tables and fields (
orders.delivery_fee); - URLs and server responses (
POST /api/orders,200); - function names (
calcDelivery(4999)).
Those are the team's decisions and they change, while the rule stays. A scenario that contains them breaks because of them, and whoever knows the rule cannot read it.
More precisely, if you are curious
The Cucumber documentation ("Writing better Gherkin") says the same: a scenario describes the behaviour of the system, not how it is built, that is, what, not how. It does not forbid the imperative style: in some contexts the details matter, but such scenarios cost more to maintain.
When is the "how" the requirement itself? When you check the accessibility of the payment form, the keyboard and the labels are the behaviour. Then the scenario says them. But the delivery rule does not depend on a button.
The idea of a shared language for the business and the team has a name in software design: the ubiquitous language of Eric Evans's Domain-Driven Design (2003). The words in the conversation, in the scenario and in the code are the same.
Test
Check yourself
Related lessons
Section titled "Related lessons"- Builds on: What a story is · Acceptance criteria · Given, When, Then · Scenario Outline and Examples
- Continues in: Bad scenarios · Living documentation · API and user interface
- Tasks on this topic: Scenarios in Gherkin