I'm using Cucumber and JUnit5 to write tests for my projects. My project uses Spring Framework and Gradle as a build tool and I use IntelliJ Idea as an editor which has Cucumber and Gradle plugins. Here is my Cucumber's runner:
package com.mycom.myproject.cucumber;
import static io.cucumber.junit.platform.engine.Constants.*;
import org.junit.platform.suite.api.*;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("src/test/resources")
@ConfigurationParameters({
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycom.myproject.cucumber.steps"),
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, value = "src/test/resources/cucumber"),
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "html")
})
public class RunCucumberTest {
}
This is my cucumberBootstrap class:
package com.mycom.myproject.cucumber;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.mycom.myproject.Application;
import io.cucumber.spring.CucumberContextConfiguration;
@CucumberContextConfiguration
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, args = "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,com.arkea.catalyst.kafka.spring.KafkaAutoConfiguration")
@ActiveProfiles({ "IC" })
public class CucumberBootstrap {
}
My steps definition class:
package com.mycom.myproject.cucumber.steps;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StepDefinition extends CucumberBootstrap {
@Quand("I want to calculate my bill")
public void iWantToCalculateMyBill() {
// some code
}
@Alors("I have this result")
public void iHaveThisResult() {
// some assertions
}
}
Here is my gradle.build file:
// Tests dependencies
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.rest-assured:rest-assured:4.1.2'
testImplementation "io.cucumber:cucumber-java:$cucumberVersion"
testImplementation "io.cucumber:cucumber-spring:$cucumberVersion"
testImplementation "io.cucumber:cucumber-junit-platform-engine:$cucumberVersion"
testImplementation "org.junit.vintage:junit-vintage-engine"
testImplementation 'org.junit.platform:junit-platform-suite:1.9.0'
implementation 'org.junit.platform:junit-platform-commons:1.9.0'
}
test {
useJUnitPlatform()
systemProperty 'java.util.logging.manager', 'org.apache.logging.log4j.jul.LogManager'
testLogging.showStandardStreams = true
testLogging.exceptionFormat = 'full'
}
My cucumber's version is 7.5.0. No matter how I change the code, I keep having the "no tests found for given includes" error and I have no idea how to change it. Do you guys have any clue?
Thanks
In your runner class you've got two problems.
@SelectClasspathResource("src/test/resources")
This selects a classpath resource. However src/test/resources is not a resource on the classpath.
To explain, consider a simple project you may have the following layout:
src
├── main
│ └── java
│ └── io
│ └── cucumber
│ └── skeleton
│ └── Belly.java
└── test
├── java
│ └── io
│ └── cucumber
│ └── skeleton
│ ├── RunCucumberTest.java
│ └── StepDefinitions.java
└── resources
├── io
│ └── cucumber
│ └── skeleton
│ └── belly.feature
└── junit-platform.properties
Here src/main/java, src/test/java and src/test/resources are different sources. When you build your project these are compiled or copied the build folder:
build
├── classes
│ └── java
│ ├── main
│ │ └── io
│ │ └── cucumber
│ │ └── skeleton
│ │ └── Belly.class
│ └── test
│ └── io
│ └── cucumber
│ └── skeleton
│ ├── RunCucumberTest.class
│ └── StepDefinitions.class
└── resources
└── test
├── io
│ └── cucumber
│ └── skeleton
│ └── belly.feature
└── junit-platform.properties
Then when running your tests, the class path is composed of your dependencies and the build/classes/java/{main,test} and build/resources/test classpath roots.
This means that io/cucumber/{Belly,RunCucumberTest,StepDefinitions}.class as well as io/cucumber/skeleton/belly.feature are all resources on the classpath.
And because @SelectClasspathResource selects a class path resource you should use @SelectClasspathResource("io/cucumber/skeleton/belly.feature"). If you have multiple features in @SelectClasspathResource("io/cucumber/skeleton") will also work.
@ConfigurationParameter(key = FEATURES_PROPERTY_NAME, ..)
The FEATURES_PROPERTY_NAME only exists because Maven and Gradle don't support JUnit5s discovery selectors from the command line. You don't need it in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With