I have a problem setting up the correct ecosystem for tests. I was following other projects, although they used Gradle, which shouldn't have a significant impact. The issue arises when I try to use the Runner with JUnit. Every time, I get 'No tests were found'. I’ve tried different paths, but it didn’t help. In my opinion, the project structure is correct, and the code should be able to reach the steps without any issues.
src -main -test -java -com.example -gui -StarterStep.java -TestRunner.java -resources -features -Test1.feature project structure
StarterStep.java
public class StarterStep
{
@Given("Start testing")
public void openBrowser(){
open("https://google.pl/");
}
}
TestRunner
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = Constants.GLUE_PROPERTY_NAME, value = "com.example.gui")
@ConfigurationParameter(key = Constants.PLUGIN_PROPERTY_NAME,
value = "pretty, summary, json:target/reports/cucumber-reports/cucumber.json,"
+ " io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm")
@ConfigurationParameter(key = Constants.FILTER_TAGS_PROPERTY_NAME, value = "@AM")
public class TestRunner
{
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>org.example</groupId>
<artifactId>JUnitTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<allure.version>2.27.0</allure.version>
<cucumber.version>7.15.0</cucumber.version>
</properties>
<dependencies>
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<version>1.10.2</version>
<scope>test</scope>
</dependency>
<!-- Cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide-video-recorder</artifactId>
<version>7.6.0</version>
<scope>test</scope>
</dependency>
<!-- Allure -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-selenide</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>${allure.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I’ve already tried changing the versions of everything one by one. The test for Cucumber is correct because I can run it from the feature level.
You're using the junit-platform-suite-api
. Which is just the API for the test engine that executes the @Suite
annotation. You should instead use junit-platform-suite
which transitively adds a dependency on both -api
and -engine
.
Further more to ensure all the right versions are used, you'll want to use dependency management for both JUnit and Cucumber.
So everything together
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.20.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</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-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-api</artifactId>
<scope>test</scope>
</dependency>
... your other non-cucumber and non junit dependencies here
</dependencies>