My project was built using Eclipse. If I run maven test from there or even the CLI, I get the result Tests run: 15. If I try to run individual cucumber feature files using the command
mvn test -Dsurefire.includeJUnit5Engines=cucumber -Dcucumber.plugin=pretty -Dcucumber.features=/path/to/individual/feature/file
Then the output is
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< restApiTest:cucumber >------------------------
[INFO] Building cucumber 0.0.1-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ cucumber ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\tiger\Documents\Code\Java\cucumber\src\main\resources
[INFO]
[INFO] --- compiler:3.11.0:compile (default-compile) @ cucumber ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ cucumber ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources from src\test\resources to target\test-classes
[INFO]
[INFO] --- compiler:3.11.0:testCompile (default-testCompile) @ cucumber ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- surefire:3.2.2:test (default-test) @ cucumber ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
Jan 11, 2024 2:14:15 P.M. io.cucumber.junit.platform.engine.DiscoverySelectorResolver warnWhenCucumberFeaturesPropertyIsUsed
WARNING: Discovering tests using the cucumber.features property. Other discovery selectors are ignored!
Please request/upvote/sponsor/ect better support for JUnit 5 discovery selectors.
See: https://github.com/cucumber/cucumber-jvm/pull/2498
Scenario Outline: Login as user # src/test/resources/restApiTest/cucumber/login.feature:14
Given the correct api endpoint as "/api/login" # restApiTest.cucumber.StepDefinitions.the_correct_api_endpoint_as(java.lang.String)
When the payload consist of "eve.holt@reqres.in" and "cityslicka" # restApiTest.cucumber.StepDefinitions.the_payload_consist_of_and(java.lang.String,java.lang.String)
And endpoint is pinged # restApiTest.cucumber.StepDefinitions.endpoint_is_pinged()
Then response status is 200 # restApiTest.cucumber.StepDefinitions.response_status_is(java.lang.Integer)
And response body contains "token" and "QpwL5tke4Pnpja7X4" # restApiTest.cucumber.StepDefinitions.response_body_contains_and(java.lang.String,java.lang.String)
Scenario Outline: Login as user # src/test/resources/restApiTest/cucumber/login.feature:15
Given the correct api endpoint as "/api/login" # restApiTest.cucumber.StepDefinitions.the_correct_api_endpoint_as(java.lang.String)
When the payload consist of "peter@klaven" and "" # restApiTest.cucumber.StepDefinitions.the_payload_consist_of_and(java.lang.String,java.lang.String)
And endpoint is pinged # restApiTest.cucumber.StepDefinitions.endpoint_is_pinged()
Then response status is 400 # restApiTest.cucumber.StepDefinitions.response_status_is(java.lang.Integer)
And response body contains "error" and "Missing password" # restApiTest.cucumber.StepDefinitions.response_body_contains_and(java.lang.String,java.lang.String)
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.658 s
[INFO] Finished at: 2024-01-11T14:14:20-05:00
[INFO] ------------------------------------------------------------------------
I have tried several online solutions but none seem to work. My pom.xml is as folllows:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>restApiTest</groupId>
<artifactId>cucumber</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.15.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
<release>9</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.7.8</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber</projectName>
<skip>false</skip>
<!-- output directory for the generated report -->
<outputDirectory>${project.build.directory}</outputDirectory>
<!-- optional, defaults to outputDirectory if not specified -->
<inputDirectory>${project.build.directory}/jsonReports</inputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
<!-- optional, set true to group features by its Ids -->
<mergeFeaturesById>false</mergeFeaturesById>
<!-- optional, set true to get a final report with latest results of the same test from different test runs -->
<mergeFeaturesWithRetest>false</mergeFeaturesWithRetest>
<!-- optional, set true to fail build on test failures -->
<checkBuildResult>false</checkBuildResult>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
My Test Runner is configured as
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("restApiTest/cucumber")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, json:target/jsonReports/cucumber.json")
public class RunCucumberTest {
}
I am now stuck and help would be appreciated?
Update: As per comment, removed the snip and added the full output and added the full pom.xml.
Modified junit-jupiter artifact to junit-jupiter-engine and update the maven-surefire-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
For the cucumber runner,add import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
as one of the imports and then add the following configuration parameter:
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "restApiTest")