I'd like to have my testers be able to organize their Given (or When or Then) steps in any order. This means the Given steps will be accumulating actions to take (database insertions, page visits, etc). Before the When steps execute, I'd like to execute the accumulation of actions to take from the Given steps. Is there a hook to do that?
-
I havent found any way to do this and it's crazy! How did the inventors think? They dont give you the AST, but a bunch of stream parser callbacks, expect you to build up the state yourself. There is also no way of declaring data dependencies or hooks when certain stages of the parsing has completed. How are you supposed to deal with this? I feel like I'm receiving events from a tokenizer and am starting to think that it would be easier to just write my own parser for the feature files! – Alexander Torstling Oct 12 '15 at 15:56
1 Answers
I don't know of a hook to achieve what you want, but I believe that the problem is that you are not cuking your scenarios properly.
It sounds as though you (it would've helped if you'd included an example scenario!) are writing imperative instead of declarative scenarios. See here for examples of an imperative and declarative scenarios. Also scenarios should be written in a technology-agnostic way so that anyone in the business can understand them, hence you should not include steps which detail "database insertion" actions.
If you were to write your scenario in a declarative fashion (i.e. detailing what action you want to execute without detailing exactly how that action will be executed) then there would be no need to execute an "accumulation of actions".
Another benefit of declarative scenarios is that they are more explicit in stating what the scenario is trying to achieve e.g With the following:
When I enter "email@domain.com" in "email"
And I enter "password1" in "password"
And I tap "login"
A reader has to deduce what the purpose of these steps are, whereas with:
Given I login using valid credentials
It's clear what the steps intent is.
-
1The intention is to write scenarios that look something like: ` Given there is a legal inventory And there is a legal buyer And I log in with valid credentials When I execute a purchase on behalf of a buyer Then a shipping invoice will be generated ` The three Given clauses could be in any order, but I don't want to handle them until all of them are there. Does that make better sense? – Rob Kinyon Jan 06 '14 at 18:57
-
Ok, more detail is good. You should put scenario in your question. You say that they can be in any order, but if this is the "happy path" it looks ok. As I suggested in the answer, you could amalgamate the three givens into one (e.g. "Given I log in to a legally ready landing page" or something along those lines), but even then you'd need to hardcode the order of actions within the new given. As the scenarios are supposed to capture business expectations, it might be worth you creating different scenarios for the different combinations. – Ben Smith Jan 07 '14 at 00:31