Scenario Outlines Vs Parameterised StepDefs

Several users have enquired about scenario outlines for Gwen. So I recently created a pull request to add support for them but am a little hesitant to merge for the following reasons:

Consider the following example taken from the pull request above.

Feature: Join Strings

   Scenario Outline: Join two strings together

     Given string 1 is "<string 1>"
       And string 2 is "<string 2>"
      When I join the two strings
      Then the result should be "<result>"

     Examples:
     | string 1 | string 2 | result   |
     | howdy    | doo      | howdydoo |
     | any      | thing    | anything |

Parameterised StepDef Approach

The above can be reduced to a single Scenario containing two steps for each Example record:

Scenario: Join two strings together
    Given "howdy" joined with "doo" should yield "howdydoo"
      And "any" joined with "thing" should yield "anything"

These steps can be bound to a step definition in Meta as follows:

  @StepDef
  Scenario: "<string 1>" joined with "<string 2>" should yield "<result>"
      Given string 1 is "$<string 1>"
        And string 2 is "$<string 2>"
       When I join the two strings
       Then the result should be "$<result>"

With this approach:

  • We achieve the same effect with just two steps (one for each example record)
  • Each step is executable in the REPL console

    CSV Data Feed Approach

    The same can also be achieved by feeding a CSV file containing header and data rows to a feature.

    CSV file:

    string 1,string 2,result
    howdy,doo,howdydoo
    any,thing,anything
    

    Feature file:

    Scenario: I join two strings together
    
        Given string 1 is "${string 1}"
          And string 2 is "${string 2}"
         When I join the two strings
         Then the result should be "${result}"
    

    A Possible Compromise

    Alternatively we could add support for scenario outlines but mandate that they be confined to Meta as step definitions.

    For example, we could declare the outline to be a StepDef in Meta as follows:

       @StepDef
       Scenario Outline: I join two strings together
    
         Given string 1 is "<string 1>"
           And string 2 is "<string 2>"
          When I join the two strings
          Then the result should be "<result>"
    
         Examples:
           | string 1 | string 2 | result   |
           | howdy    | doo      | howdydoo |
           | any      | thing    | anything |
    

    And then we could call it in features as follows:

    Given I join two strings together
    

    But declaring rows of data in meta is also not ideal.

    Do we need Scenario Outlines?

    I’ve created a pull request to add support for scenario outlines in feature files but cannot support them in the REPL. I’ve shown here that we can achieve the same effect using parameterised StepDefs or CSV data feeds. I’ve also proposed a compromised alternative.

    I’d like to know your thoughts.

    Advertisements