I'm using since a while Cucumber with JUnit 4 but currently I need to use it for the first time with JUnit 5 and it doesn't seem to work. I have the following dependencies:
...
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<scope>test</scope>
</dependency>
...
I'm using the failsafe maven plugin configured as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<groups>profileServer</groups>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/jacoco-it.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
The test class looks as follows:
@Cucumber
@Tag("profileServer")
public class CustomersCucumberIT
{
}
Here I'm using the @Tag annotation which is replacing JUnit4 @Category in order to selectively execute tests based on the element configured in the failsafe maven plugin, here above.
The fetaures file is in src/main/test/resources/features/it and its name is customers.features.
Last but not least, here is the steps class:
@Tag("profileServer")
public class CustomersCucumberSteps
{
...
}
Running the verify goal display the following output: ┌─────────────────────────────────────────────────────────────────────────────┐ │ Share your Cucumber Report with your team at https://reports.cucumber.io │ │ Activate publishing with one of the following: │ │ │ │ src/test/resources/cucumber.properties: cucumber.publish.enabled=true │ │ Environment variable: CUCUMBER_PUBLISH_ENABLED=true │ │ JUnit: @CucumberOptions(publish = true) │ │ │ │ More information at https://reports.cucumber.io/docs/cucumber-jvm │ │ │ │ To disable this message, add cucumber.publish.quiet=true to │ │ src/test/resources/cucumber.properties │ └─────────────────────────────────────────────────────────────────────────────┘
but simply skips the test execution as if there weren't any. Previously, with JUnit 4 I was using @CucumberOptions in order to set the features location. But with JUnit 5 this annotation isn't supported any more and I don't find any other. It seems that it is supposed to be discovered.
I've seen a couple of posts mentioning that the features files might be configured in the failsafe or surefire maven plugin with:
...
<options>
<configurationParameters>
...
</configueationParameters>
</options>
...
but this syntax doesn't seem to be supported and, anyway, I didn't find any parameter that I could use in order to configure where the steps are.
Could someone please enlighten me on that and provide also a simple example ?
Many thanks in advance.
Seymour