Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specflow Given When Then BUT?

I have been using SpecFlow for a while, without making use of the "but" logic.

Considering the following scenario:

Scenario: Kiran logs into the system but doesn't click remember me
Given I have a username of 'Kiran'
And a password of 'password'
When I chose login
But I don't chose remember me
Then I should be logged in
And Taken to the home screen
But My username should not be remembered

Couldn't the "but" steps just be interchanged with "and"?

Is there any advantage to using "but"?

Am I right in thinking that this is purely for readability purposes?

I look forward to hearing your thoughts on this.

Many thanks, Kiran

like image 206
K-Dawg Avatar asked Jun 10 '15 17:06

K-Dawg


1 Answers

Yes you are right, "and" and "but" are inter-changeable in the gherkin syntax.

However in my experience "and" is used when you are indicating that a user should carry out an action, whereas "but" is best suited to when you want to highlight that a user should not perform an action; this is because "but" in the English language is generally used in a negative context.

Hence in your example:

But I don't chose remember me

Is a good use of "but" as they are not performing an action. Additionally using "but" makes the intent of the test explicit and removes any possible ambiguities.

like image 72
Ben Smith Avatar answered Oct 25 '22 10:10

Ben Smith