Replies: 4 comments 2 replies
-
|
This is something that probably wouldn't live inside a single feature. Because I'm assuming you only want this to run once for the entire test execution. If not you're coupling your tests too rigidly. If so, then there are mechanisms in-place. Lean on a |
Beta Was this translation helpful? Give feedback.
-
|
Alternatively, if the dataset is only used for some scenarios, but not all. And if the dataset is reusable between scenarios, caching would allow you to reuse the dataset after it has been created. The simplest example would look something like this: static Dataset dataset;
@Given("a lengthy and resource intensive preparation")
public void setupData(){
if(dataset == null) {
dataset = // create data set here.
}
return dataset;
} |
Beta Was this translation helpful? Give feedback.
-
|
I was struggling with the same task and solved it by caching at the step-definition layer rather than at the feature layer.
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for all the replies! Caching and before all hides the preparation work from the readers of the feature/scenarios. On the one hand this could sometimes be treated as implementation details. However, Cucumber/Gherkin allows us to describe features/scenarios in such a way that is readable for all concerned. If the setup is time and resource intensive, is it something we should completely hide from readers of the feature file? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the background steps get executed each time a scenario runs. For some scenarios the background could take significant time and resources. When the background steps create a dataset that is read in multiple scenarios the execution time of the scenarios is mainly influenced by the background.
I would propose to introduce a new keyword
shared background(my first suggestion). That would function similar to Java JUnit 5 BeforeAll.Example:
The regular background is executed each time, the shared background only once.
In some situations parallelism could be an alternative to complete scenarios sooner, however the resource usage remains.
What do you think of this proposal?
Regards,
Michiel
Beta Was this translation helpful? Give feedback.
All reactions