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

Sar*_*ara 2 java testing junit cucumber junit5

我使用 Junit5 和 Cucumber 创建了一个小片段 Spring Boot 应用程序。因为我需要使用 Junit5 我正在使用cucumber-junit-platform-engine它不支持注释CucumberOptions

正如在cucumber.io 网站上引用的:

当运行程序(即cucumber-junit-platform-engine)不提供属性解析功能时,Cucumber 将按优先级从系统属性、环境变量和cucumber.properties 文件中解析属性。

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

cucumber.plugin=json:target/cucumber-reports/,pretty
Run Code Online (Sandbox Code Playgroud)

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

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

我也尝试将文件放在src/main/resources下面src/main/test/cucumber.demo(功能文件所在的位置),但这些尝试都没有奏效。知道为什么文件被忽略了吗?

这是我的跑步者课程:

cucumber.plugin=json:target/cucumber-reports/,pretty
Run Code Online (Sandbox Code Playgroud)

和我的步骤定义类:

@Cucumber
public class CucumberTest {
    
}
Run Code Online (Sandbox Code Playgroud)

mpk*_*nje 5

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

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