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
  • Published by

    Branko Juric

    Imperative by day and functional by night. Co author of the Gwen automation platform.

    2 thoughts on “Scenario Outlines Vs Parameterised StepDefs”

    1. After spending sometime playing with scenario outlines, I’m thinking it is well worth including support for them in Gwen. They’re quite powerful. Also, I’ve put some more commits into the PR to enable declaring them as StepDefs in addition to just running them inline. This will allow users to reuse and call them from anywhere (including backgrounds).

      Like

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s