黄瓜测试未读取 cucumber.properties 文件

Cucumber tests not reading cucumber.properties file

我使用 Junit5 和 Cucumber 创建了一个小片段 Spring 启动应用程序。 因为我需要使用 Junit5,所以我使用的是 cucumber-junit-platform-engine,它不支持注释 CucumberOptions

引自cucumber.io 网站:

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.

因此,我将以下名为 cucumber.properties 的文件添加到我的目录 src/test/resources 中,内容如下:

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

然而,当我 运行 我的测试时,这个文件似乎被忽略了,因为没有生成报告,而如果我通过 cli 参数传递相同的 属性,例如:

mvn test -Dcucumber.plugin=json:target/cucumber-reports/,pretty 它会生成预期的 json 报告。

我也试过将文件放在 src/main/resourcessrc/main/test/cucumber.demo 下(功能文件所在的位置),但是这些尝试中有 none 成功了。知道为什么文件被忽略了吗?

这是我的 Runner class:

@Cucumber
public class CucumberTest {
    
}

和我的步骤定义 class:

@CucumberContextConfiguration
@SpringBootTest
public class StepDefinition {

    @Autowired
    String bean;

    //Step Definition 
    (...)

}

当您通过 cucumber-junit-platform-engine 将 Cucumber 与 JUnit5 一起使用时,测试由 JUnit 平台 运行 进行。 JUnit 平台提供 属性 解析功能。

有几种不同的方法可以为 JUnit 平台提供属性。其中之一是 junit-platform.properties 文件。您可以在此处阅读更多详细信息: