2
votes

I have a Maven / Spring Boot 2.3.3 application with JUnit 5 and Cucumber (v6.5.1) tests.

The thing is that I can run OK either Unit and Integration tests via Maven, but it does not run Cucumber.

Cucumber Runner:

package cucumber.salad.api.integration.cucumber;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "classpath:features",
        plugin = { "pretty", "html:target/reports/cucumber", "json:target/cucumber.json", "usage:target/usage.jsonx", "junit:target/junit.xml" },
        extraGlue = "cucumber.salad.api.integration.cucumber.steps"
)
public class CucumberTest {
}

Cucumber Spring Context Config:

package cucumber.salad.api.integration.cucumber;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.ContextConfiguration;
import cucumber.salad.App;
import io.cucumber.spring.CucumberContextConfiguration;

@ContextConfiguration
@CucumberContextConfiguration
@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class CucumberSpringContextConfig {
    
    @LocalServerPort
    protected int port;
}

Steps:

package cucumber.salad.api.integration.cucumber.steps;
import static org.assertj.core.api.Assertions.assertThat;
import org.springframework.beans.factory.annotation.Autowired;
import cucumber.salad.api.integration.cucumber.CucumberSpringContextConfig;
import cucumber.salad.api.service.DummyService;
import io.cucumber.java.en.*;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SaladStepDefinitions extends CucumberSpringContextConfig {
    
    // steps here
}

I use Surefire and Failsafe in the Maven pom.xml: https://github.com/danieldestro/cucumber-salad/blob/master/pom.xml

Here is the project repository: https://github.com/danieldestro/cucumber-salad

Command I run:

mvn clean test integration-test

But there is not a sign from Cucumber test execution.

I am missing anything or doing something wrong?

3
Have you tried the latest Spring Boot version? I'm thinking it's a dependency mismatch with JUnit/Cucumber/SurefireM.P. Korstanje
I am running on the latest Spring Boot (2.3.3). I will try with older versions.danieldestro
Well, I tried Spring Boot 2.2.9 and 2.3.3 with Cucumber 6.4.0 and 6.6.0 and no luck here!danieldestro

3 Answers

4
votes

You're using cucumber-junit which integrates Cucumber with JUnit 4. You're also using JUnit 5. JUnit 5 can execute JUnit 4 tests through the junit-vintage-engine. However you've excluded this engine from your classpath.

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Either include the the junit-vintage-engine or use the cucumber-junit-platform-engine instead of cucumber-junit.

2
votes

I had the same problem; when I ran the mvn test command the cucumber tests were not executed. I was using:

  • spring-boot:2.5.0
  • Java 11 (OpenJDK Zulu 11.0.11)
  • Dependencies
    • cucumber-core: 6.10.4
    • cucumber-java:6.10.4
    • cucumber-junit:6.10.4
    • cucumber-spring:6:10.4

What I did was exclude the junit-jupiter-engine from the spring-boot-starter-test dependency.

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
0
votes

If you use junit 5, all you have to do is to add the two cucumber dependencies (cucumber-java and cucmber-junit by excluding junit 4 from all your dependencies).

furthermore, import junit-vintage-engine so cucumber can use it.

Explanation :

If you import junit 4, all the tests with jupiter (junit 5) will be ignored, Or vice versa. You can test it by adding two classes with each version of junit (by adding @Test of each version on each class). Only one version will run.