Specflow Given When Then BUT?
Asked Answered
W

1

8

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

Westbound answered 10/6, 2015 at 17:48 Comment(0)
C
13

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.

Cower answered 10/6, 2015 at 20:21 Comment(5)
Thank you Ben! I have been pondering this all evening.Westbound
No problems :D it is a good question and it helps me solidify my understanding when answering such a question.Cower
I think it is good to have a syntax to say Do this and Do NOT do that. Thanks for the explanation.Earplug
@PrimeByDesign As it's nearly been a year(!) are you going to mark this as answered?Cower
@BenSmith No but now I think it's time to mark it as answered! Haha sorry I missed your comment back in May.Westbound

© 2022 - 2024 — McMap. All rights reserved.