6
votes

I am trying to run Cucumber from Gradle using tags to run different sets of tests

In dev I want to run the Eat cukes scenario:

./gradlew -Dcucumber.options="--tags @dev" clean test

And in pro I want to run the Eat mushrooms scenario:

./gradlew -Dcucumber.options="--tags @pro" clean test

The problem is that gradle/cucumber seems to be ignoring the cucumber.options tag information and always runs all the tests. I have tried the same example with Maven and it works. Unfortunately I need this to run with Gradle. Any ideas?

My test runner is junit-jupiter 5.1.0 with junit-platform-launcher 1.1.0, junit-jupiter-engine 5.1.0 and junit-vintage-engine 5.1.0.

@RunWith(Cucumber.class)
public class CucumberTest {

}

Feature:

Feature: Restaurant

  @dev
  Scenario: Eat cukes

    Given I have 10 cukes in my belly
    Then I eat 1 more cukes

  @pro
  Scenario: Eat mushrooms

    Given I have 10 mushrooms in my belly
    Then I eat 1 more mushrooms

Dev step definition:

public class RestaurantStepDef implements En {

    public RestaurantStepDef() {
        Given("I have (\\d+) cukes in my belly", (Integer cukes) -> System.out.format("Cukes: %n\n", cukes));
        Then("I eat (\\d+) more cukes", (Integer number) -> assertEquals((Integer) 2, number));
    }

}

Pro step definition:

public class RestaurantStepDef2 implements En {

    public NavegationStepDef2() {
        Given("I have (\\d+) mushrooms in my belly", (Integer cukes) -> System.out.format("Mushrooms: %n\n", cukes));
        Then("I eat (\\d+) more mushrooms", (Integer number) -> assertEquals((Integer) 2, number));
    }

}
1
It helped indeed! Thanks!codependent

1 Answers

0
votes

Gradle forks the test execution into a different JVM so the initial System properties are not carried over

Add this to your gradle file

test { systemProperty "cucumber.options", System.getProperty("cucumber.options") }