Reputation: 105
I am trying to run cucumber 7.8.0 with JUnit 5. These are my dependencies:
package com.example.demo;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import static io.cucumber.core.options.Constants.FEATURES_PROPERTY_NAME;
import static io.cucumber.core.options.Constants.GLUE_PROPERTY_NAME;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("cucumber/mytest.feature")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example.steps")
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "classpath:cucumber/mytest.feature")
public class RunCucumberTest {
}
I would like to run cucumber using maven-surefire-plugin (version: 2.22.2), but it says no junit test is found. When I debug, it seems that SelectClasspathResource is never loaded.
Can someone please advice?
Thanks
Upvotes: 4
Views: 2501
Reputation: 23
You need to add below dependencies to your pom.xml file:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
Next, you need to configure surefire plugin as follows, remember to change the value in the <test> tag to your runner file path from source root :
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<test>com.learning.springboot.first.time.runners.runner.java</test>
</configuration>
</plugin>
</plugins>
Upvotes: 1