Reputation: 29669
My question is about how should I write Gherkin through multiple state transitions?
On this page (http://docs.behat.org/en/v2.5/guides/1.gherkin.html) it says:
whens:
The purpose of When steps is to describe the key action the user performs
(or, using Robert C. Martin’s metaphor, the state transition).
... and he even provides an example of using multiple WHEN's.
So, with the purpose of replacing Selenium tests (that go through state transitions during the test) with faster Cucumber tests, should I use a second WHEN statement for a transition during a test or should I have only 1 WHEN and use a THEN instead for that state transition?
Given one thing
When I open my eyes
Then I see something
But I don't see something else
When I close my eyes
Then it is dark again
And I am asleep again
Upvotes: 0
Views: 201
Reputation: 514
Generally speaking, such scenarios should be split up - one scenario to check the open->close transition and one for the reverse. They will be less brittle that way and provide more accurate information in case of failure.
However, when you are exercising the UI, time is always a sensitive issue. If you can quickly/easily achieve the starting state, then it's a non-issue, you do the split. Often, that's not the case, and you have to choose between test execution speed and maintainability of your gherkins. If you don't overdo chaining such state-transitions, you may be able to still keep your gherkins well maintainable.
Be warned that eventually, you'll overcomplicate it because it will be so much easier to add every minor thing that you will not be able to resist the temptation. And next thing you know, your god-object-like Frankenstein will be copied all over the place by team members, before you could say "Szenariogrundriss."
Upvotes: 2