Cucumber 7.11.0 cant find feature files?

768 Views Asked by At

Im trying to use Cucumber 7.11.0 to run my feature files. But it doesn't seem to be able to find them. I am trying to run as part of the maven verify stage with maven-failsafe-plugin

Here is my test runner class:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.app.rs.api.cucumber")
public class TestRunner {}

My Project structure:

| /src
| - /test
| -- /java
| --- /com/app/rs/api/cucumber
| ---- /stepdefinition
| ----- StepDef.java
| ---- TestRunner.java
| -- /resources
| --- /features
| ---- test.feature

When I try to run my TestRunner I get the following error message

Internal Error occurred.
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-platform-suite' failed to discover tests

My pom.xml:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>7.11.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit-platform-engine</artifactId>
    <version>7.11.0</version>
    <scope>test</scope>
</dependency>

<dependency>
   <groupId>org.junit.jupiter</groupId>
   <artifactId>junit-jupiter</artifactId>
   <version>5.9.2</version>
   <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-suite</artifactId>
    <version>1.9.2</version>
    <scope>test</scope>
</dependency>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0-M8</version>
    <configuration>
        <forkCount>0</forkCount>
        <useSystemClassLoader>false</useSystemClassLoader>
        <skip>${release}</skip>
    </configuration>
    <executions>
       <execution>
          <goals>
             <goal>integration-test</goal>
              <goal>verify</goal>
          </goals>
       </execution>
    </executions>
</plugin>
2

There are 2 best solutions below

0
Maria On

Maybe try to specify the path like:

features="src/test/resources" in @SelectClasspathResource("features"), if it is possible, coz in the older versions of Cucumber we have to use it like: @CucumberOptions(features="src/test/resources") so maybe the new version expects smth similar to this

5
M.P. Korstanje On

By using @SelectClasspathResource("features") you are instructing JUnit to tell the Cucumber Test Engine to look for tests in the features package on the classpath.

However your project does not follow the Maven Standard Directory Layout. When following this structure your classes should be under scr/test/java.

This means that either:

  1. you have configured Maven differently and changed the configuration such that src/test/resources isn't copied to target/test-classes.

  2. You are not using Maven to run your tests but an IDE instead. If so your IDE is not configured correctly and does not use the src/test/resources as a classpath root.

You can work around this by instructing JUnit to tell Cucumber to look for tests in a different location. You can find all the options for this in the org.junit.platform.suite.api package. You could try @SelectDirectories("src/test/resources").

Though you should probably fix your project structure. You can use the cucumber-java-skeleton as an example.