I am a bit confused with the way people write statements in the Gherkin language to describe various actions performed for acceptance testing.
In some articles people use "I" and in some articles people use "User".
The same is the case for reaction (Then
) statements:
Case 1 --> xyz page should be displayed
Case 2 --> xyz page is displayed
Ex 1:
Given statement abc
When user performs action A
Then screen xyz should be displayed
Ex 2:
Given statement abc
When I perform action A
Then screen xyz is displayed
Is it better to write "user" or "I", and is it better to write "should be" or "is", so that my BDD scenarios are presentable and correct as per standards?
References to any article would also be a great help. Thanks in advance.
The Given-When-Then formula is a template intended to guide the writing of acceptance tests for a User Story: (Given) some context. (When) some action is carried out. (Then) a particular set of observable consequences should obtain.
Given-When-Then steps must appear in order and cannot repeat. A Given may not follow a When or Then, and a When may not follow a Then. The reason is simple: any single When-Then pair denotes an individual behavior.
Steps. Each step starts with Given , When , Then , And , or But . Cucumber executes each step in a scenario one at a time, in the sequence you've written them in. When Cucumber tries to execute a step, it looks for a matching step definition to execute.
Both are correct, and have different benefits.
Dan North, who invented BDD, says he prefers 1st person ("I"), as it allows him to put himself in the user's shoes. However, he's often used 3rd person ("he / she / the customer") as he does in his introductory article.
The first-person use can help to make a scenario fit with the standard story template:
As <a stakeholder>
I want <something>
So that <goal>.
If the stakeholder is the user, then it makes sense to use "I" again in the scenario.
However, sometimes scenarios' outcomes aren't really for the benefit of the user.
As the moderator of the site
I want users to prove that they're human
So that I can limit spam.
In this case, it would be odd to put the scenario in the perspective of the user, because the user doesn't really want to be filling in that captcha box. We'd probably use 3rd person here.
Given an odd-looking number "31" on a door frame
When the user identifies the number as "31"
Then the system should authenticate them as being human.
You may also find that you have more than one stakeholder whose outcomes are important. In that case, putting the scenario in the 3rd person can help to spot any other outcomes or important stakeholders that might not have been included.
Given Suzanne searches for a taxi for 4pm to take her to hospital
And the estimated price is $23
When she books the taxi
Then she should get a confirmation email
And the driver should be notified of the trip
And she should be charged $23.
Because both Suzanne, and the driver, and Uber, are all involved in this scenario, it makes more sense to put them in the 3rd person.
I tend to prefer the 3rd person, especially for large products with a lot of scenarios, as I find it confusing to have to switch 1st person roles, and it allows for consistency. It also means you can give the actors in the scenarios memorable names and talk about them more easily ("The one where Clarence Clumsy types his number in wrong", for example).
However, remember that when you're talking to your stakeholders to get hold of these scenarios, the most important thing is the conversation. Write down their words as closely as you can, and only compromise the language afterwards when you come to rephrase it using Gherkin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With