Search code examples
javacucumbercucumber-jvmcucumber-javacucumber-junit

no tests executed after migrating to cucumber 7.x


I upgraded recently my Spring Boot project to the latest cucumber-java (7.2.3), and I am facing some issues.

I am able to have the expected behavior, but only by using the now deprecated @Cucumber annotation. the deprecation note says that we should "use the JUnit Platform Suite to run Cucumber"

unfortunately, there are not many examples available (most of them refer to previous versions).

my working code with the deprecated annotation is simply :

package service.test.acceptance;

import io.cucumber.junit.platform.engine.Cucumber;


@Cucumber
public class RunCucumberIntegrationTest {
}

with these dependencies :

  testImplementation group: 'io.cucumber', name: 'cucumber-java', version: libraryVersions.cucumber
  testImplementation group: 'io.cucumber', name: 'cucumber-junit', version: libraryVersions.cucumber
  testImplementation group: 'io.cucumber', name: 'cucumber-spring', version: libraryVersions.cucumber
  testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine', version: libraryVersions.cucumber

(and the Junit stuff that comes with Spring Boot Test, so Junit 5.5.2 in my case)

I tried this :

package service.test.acceptance;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;

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;

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("service/test/acceptance")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value ="service.test.acceptance.integration")
public class RunCucumberIntegrationTest {

}

I needed to add these 2 dependencies so tht it compiled :

testImplementation group: 'org.junit.platform', name: 'junit-platform-suite', version: '1.8.2'
testImplementation group: 'org.junit.platform', name: 'junit-platform-suite-api', version: '1.8.2'

my steps definition are in service.test.acceptance.integration package (in src/test/java), while my feature files are in service/test/acceptance folder (in src/test/resources).

When I run gradlew test, the build is green, but no test gets executed and there's no warning or anything.

any idea of what I am missing ?


Solution

  • Thanks to suggestions by @paul58914080 and @m-p-korstanje , I was able to make it work : thanks a lot !

    It was indeed a version incompatibility between the junit and cucumber versions I was using.

    This is what I ended up having :

    //override the junit version that comes with my version of Spring, and pick one compatible with Cucumber
    ext['junit-jupiter.version'] = '5.8.2'
    

    Then in the dependencies block :

    testImplementation(platform("io.cucumber:cucumber-bom:7.2.3"))
    
    testImplementation group: 'io.cucumber', name: 'cucumber-java'
    testImplementation group: 'io.cucumber', name: 'cucumber-spring'
    testImplementation group: 'io.cucumber', name: 'cucumber-junit-platform-engine'
    
    testImplementation group: 'org.junit.platform', name: 'junit-platform-suite'
    
    
    //this one was already there.. just mentioning it for sake of being exhaustive
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    

    I didn't need to touch my RunCucumberIntegrationTest class.