Search code examples
cucumbercucumber-junitcucumber-java

Execute certain Examples from Scenario Outlines


I have to execute certain Examples from Scenario Outlines.

Let's see the following example:

Feature: Temp

Scenario Outline: Test.Something.On.<environment>
  When action is performed on "<environment>"

Examples:
 |environment|
 |lab        |
 |prod       |

I would like to execute only the example with lab from the upper presented Examples.

I tried the followings:

  • Filter by line number: mvn clean test -Dcucumber.options="src/test/resources/features/Temp.feature:8" - this way only the lab scenario was executed, however this is not a long term solution;
  • Filter by name: mvn clean test -Dcucumber.options="name lab" - it works for Scenario but not for Scenario Outline even if the name of the scenario will be Test.Something.On.lab;
  • decompose the Scenario Outline in Scenarios and tag the proper scenarios with @lab and @prod - I hate code duplication and the subsequent maintenance, therefore I hope there is an another solution for this.

Any suggestions? Big thanks.

Another sub-keywords: maven, java, cucumber-java8, cucumber-junit, junit


Solution

  • Use two examples in yoour scenario outline and tag each example in a similar way as you have done in your third option. That should give you the behaviour you are asking for.