Home > Net >  Run Cucumber tests with and without Spring context
Run Cucumber tests with and without Spring context

Time:01-05

I am trying to integrate Cucumber in an existing Spring Boot project.
The current project is a single Maven module.
The unit tests (without Spring context) and integration tests (with Spring context) are combined in the same tests folder.

What I'd like to do is being able to adapt both my unit tests and integration tests.
But as soon as I add the cucumber-spring dependency (to be able to run a Spring context alongside the specification) it asks for all tests in the folder to be annotated with @CucumberContextConfiguration.

Below is my test suite configured to pick up the test specification.

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("org/example/project")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
public class CucumberTest {
}

Is it possible to combine the 2 kinds of tests or not? If yes how?

For info I am using:

  • Cucumber 7.1.0
  • Spring Platform Suite 1.8.2
  • JUnit 5.8.2

CodePudding user response:

You can control the object factory that is used through the cucumber.object-factory property. So suppose you have one, or more object factories as your dependency:

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-spring</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <scope>test</scope>
</dependency>

Then you can select spring with:

@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.spring.SpringFactory")

Pico container with:

@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")

Or since v7.1, neither with:

@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.core.backend.DefaultObjectFactory")
  •  Tags:  
  • Related