'Call before hook once for test with a set of examples in Cucumber

I'm trying to run a scenario with Cucumber that is using a before hook to load a dataset. My problem is the Scenario has a set of examples and the before step is called before every example, meaning I'm getting stopped at the start of the second example because of DatabaseUnitExceptions.

Is there some way to only call the before hook once for the whole scenario and not for each example?

Cheers



Solution 1:[1]

As stated by Gaƫl; each example under a scenario outline is a scenario. So Cucumber will run the @Before hook before each scenario / example. (Scenario and example being synonyms to Cucumber).

If you want to run a hook before all scenarios, have a look at @BeforeAll. Please refer to the Cucumber documentation on hooks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marit