Sara
Sara

Reputation: 406

Cucumber tests not reading cucumber.properties file

I created a small snippet Spring Boot application using Junit5 and Cucumber. Because I need to use Junit5 I am using cucumber-junit-platform-engine which does not support the annotation CucumberOptions

As quoted in cucumber.io website:

When property parsing functionality is not provided by the runner (i.e. cucumber-junit-platform-engine) Cucumber will in order of precedence parse properties from system properties, environment variables and the cucumber.properties file.

Because of this I added the following a file named cucumber.properties to my directory src/test/resources with the following content:

cucumber.plugin=json:target/cucumber-reports/,pretty

Yet, when I run my tests this file seems to be ignored as no reports are generated while if I pass the same property through cli arguments such as:

mvn test -Dcucumber.plugin=json:target/cucumber-reports/,pretty it generates the expected json reports.

I have also tried putting the file under src/main/resources and under src/main/test/cucumber.demo (where the feature files are located), but none of these attempts worked. Any idea why the file is being ignored?

Here is my Runner class:

@Cucumber
public class CucumberTest {
    
}

and my Step Definition class:

@CucumberContextConfiguration
@SpringBootTest
public class StepDefinition {

    @Autowired
    String bean;

    //Step Definition 
    (...)

}

Upvotes: 8

Views: 14411

Answers (1)

M.P. Korstanje
M.P. Korstanje

Reputation: 12019

When you are using Cucumber with JUnit5 through the cucumber-junit-platform-engine the tests are run by the JUnit platform. The JUnit Platform provides property parsing functionality.

There are several different ways to provide properties to the JUnit Platform. One of them being the junit-platform.properties file. You can read about it in more detail here:

Upvotes: 8

Related Questions