Details
Description
Before/AfterScenario has parameter uponType that determines when it will run. NORMAL type is run once for all the scenario cases; EXAMPLE type is run for each scenario case.
I am using the term "scenario case" for each row of the examples table (in case of parametrised scenarios) or the scenario itself (in case of "normal" scenarios).
When you want to define e.g. Before Scenario step, that will run before every scenario case, regardless whether it is parametrised or not, you must do something like this:
// before scenario will be called 2x for the first scenario case private boolean initialized; @BeforeScenario public void beforeScenario() { if (!initialized) { // do some stuff initialized = true; } } @BeforeScenario(uponType = ScenarioType.EXAMPLE) public void beforeExample() { beforeScenario(); }
This is annoying and should be fixed. There are some ways how to fix it I can think of:
- simple: Add another value to ScenarioType enum (e.g. ANY). But in this case, the name of the enum starts to feel bad.
- more work: Add annotation, e.g. @BeforeScenarioCase
What do you think is better? Am I missing something? Propose a solution and I can submit a patch.
Activity
Daniel Kolman
made changes -
Field | Original Value | New Value |
---|---|---|
Attachment | ScenarioTypeANY.diff [ 65505 ] |
Daniel Kolman
made changes -
Patch Submitted | Yes [ 10070 ] | |
Testcase included | yes [ 10040 ] |
Mauro Talevi
made changes -
Fix Version/s | 3.9.2 [ 20180 ] | |
Summary | Before/After scenario that would run before/after any scenario, all the tim | Add ScenarioType.ANY to allow @Before/AfterScenario to run before/after any scenario |
Mauro Talevi
made changes -
Resolution | Fixed [ 1 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |
Adding an ANY value to ScenarioType is the best option. Doesn't particularly feel out of line with the name.
Please provide a patch for this, if possible via git: http://jbehave.org/how-to-contribute.html