2

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 ?

Vincent F
  • 6,523
  • 7
  • 37
  • 79
  • 1
    Your dependency list looks a bit short https://github.com/cucumber/cucumber-java-skeleton/blob/main/build.gradle.kts#L4 – M.P. Korstanje Mar 10 '22 at 20:32
  • you're right, I could have been clearer in my original post. I've just edited it to mention the dependencies I have initially. – Vincent F Mar 10 '22 at 21:50
  • I'm guessing here, but if you use Gradle to list your dependencies you'll find that you're using an older version of JUnit then the one Cucumber was made for. Make sure your dependencies converge. – M.P. Korstanje Mar 11 '22 at 07:39
  • Note that the JUnits version is the JUnit Platform version+4. So ideally you use their bom (or over ride the version spring tells you to use, haven't used Gradle much). – M.P. Korstanje Mar 11 '22 at 07:41

2 Answers2

3

Can you try with the following dependencies

pom.xml

<properties>
   <junit-jupiter.version>5.8.2</junit-jupiter.version>
   <cucumber.version>7.2.3</cucumber.version>
</properties>
....
<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-suite</artifactId>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>io.cucumber</groupId>
  <artifactId>cucumber-java8</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-spring</artifactId>
  <version>${cucumber.version}</version>
  <scope>test</scope>
</dependency>

RunCucumberExampleTest.java

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/example.feature")
@ConfigurationParameters({
  @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "packagename.cucumber"),
  @ConfigurationParameter(key = FILTER_TAGS_PROPERTY_NAME, value = "@Example"),
  @ConfigurationParameter(key = JUNIT_PLATFORM_NAMING_STRATEGY_PROPERTY_NAME, value = "long"),
  @ConfigurationParameter(key = PLUGIN_PUBLISH_QUIET_PROPERTY_NAME, value = "true"),
  @ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "json:target/cucumber/cucumber.json")
})
public class RunCucumberExampleTest {}

And since you are using spring (and if you are using lambda) you can have a configuration like

SpringCucumberTestConfig.java

@SpringBootTest(classes = ExampleApplication.class, webEnvironment = RANDOM_PORT)
@CucumberContextConfiguration
@ActiveProfiles("test")
public class SpringCucumberTestConfig {}
paul58914080
  • 282
  • 3
  • 8
3

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.

Vincent F
  • 6,523
  • 7
  • 37
  • 79