java - 黄瓜测试不读取 cucumber.properties 文件
问题描述
我使用 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
然而,当我运行我的测试时,这个文件似乎被忽略了,因为如果我通过 cli 参数传递相同的属性,则不会生成任何报告,例如:
mvn test -Dcucumber.plugin=json:target/cucumber-reports/,pretty
它生成预期的 json 报告。
我也尝试将文件放在src/main/resources
下面src/main/test/cucumber.demo
(功能文件所在的位置),但这些尝试都没有奏效。知道为什么文件被忽略吗?
这是我的跑步者课程:
@Cucumber
public class CucumberTest {
}
和我的步骤定义类:
@CucumberContextConfiguration
@SpringBootTest
public class StepDefinition {
@Autowired
String bean;
//Step Definition
(...)
}
解决方案
当您通过 JUnit5 使用 Cucumber 时,cucumber-junit-platform-engine
测试由 JUnit 平台运行。JUnit 平台提供属性解析功能。
有几种不同的方法可以为 JUnit 平台提供属性。其中之一是junit-platform.properties
文件。您可以在此处更详细地了解它:
推荐阅读
- postgresql - 如何在postgresql中创建函数选择所有列
- node.js - Nodejs Put请求抛出400 Bad request Error
- html - 如何快速显示图像
- javascript - 无法将数据从 Angular.js 发布到 Node.js
- laravel-5 - Laravel 雄辩的关系与 2 个外键
- wordpress - 短代码在自定义 wordpress 主题中不起作用
- reactjs - 带有 ReactJS、Webpack 和 Babel 的 Hello World
- json - 使用 POST 方法时 Angular 6 中的 TypeError 循环对象值
- python - 销售速度定义为 sales/running_days
- angular - 如何通过 Angular 传递 URL?