JBehave
  1. JBehave
  2. JBEHAVE-1008

Add ScenarioType.ANY to allow @Before/AfterScenario to run before/after any scenario

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.9.1
    • Fix Version/s: 3.9.2
    • Component/s: Core
    • Labels:
      None
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      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

        Hide
        Mauro Talevi added a comment -

        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

        Show
        Mauro Talevi added a comment - 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
        Hide
        Daniel Kolman added a comment -

        Attached patch with implementation of ScenarioType.ANY.

        Show
        Daniel Kolman added a comment - Attached patch with implementation of ScenarioType.ANY.
        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
        Hide
        Mauro Talevi added a comment -

        Applied with thanks

        Show
        Mauro Talevi added a comment - Applied with thanks
        Mauro Talevi made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel Kolman
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: