java - Java Maven Cucumber 如何从命令行正确地重新运行测试?
问题描述
嗨,我正在使用我目前正在使用 Cucumber 6.8.1 版,我正在尝试弄清楚如何解决重新运行失败的测试。我已经破解了我自己的解决方案,但感觉不正确。为了
maven clean install
为了检测测试运行者,我将 Test 附加到他们的名字中:
@RunWith(Cucumber.class)
@CucumberOptions(plugin = { "de.monochromata.cucumber.report.PrettyReports:target/cucumber", "rerun:target/rerun.txt" })
public class CucumberRunnerTest {
}
和
@RunWith(Cucumber.class)
@CucumberOptions(
features = "@target/rerun.txt",
plugin = {"pretty", "html:target/site/cucumber-pretty",
"json:target/cucumber.json"}
)
public class RerunningTest {
}
现在这可行,但它似乎有点hacky。因为像这样的命令
mvn clean install -Dcucumber.glue="cucumber" \
-Dcucumber.plugin="de.monochromata.cucumber.report.PrettyReports:target/cucumber" \
-Dcucumber.plugin="rerun:target/rerun.txt"
应该工作,但不工作。构建成功,但没有运行测试。就像 Dcucumber 被 Maven 忽略了一样。但是,在将“测试”附加到跑步者之后,然后运行上面的命令会使用两个跑步者,因为它们被视为感觉错误的测试。
所以我的问题是如何让 Dcucumber 正常工作?
解决方案
如果您不命名您的测试类*Test
,那么 Surefire 将无法识别它。命名约定明智,尝试使用RunCucumberTest
。它不是太丑陋。
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html
测试的包含和排除
默认情况下,Surefire 插件会自动包含所有具有以下通配符模式的测试类:
"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test". "**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test". "**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests". "**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
如果测试类不遵循任何这些命名约定,则配置 Surefire 插件并指定要包含的测试。
推荐阅读
- swift - Xcode 11 - Swift 包管理器找不到清单
- renjin - Renjin: How to clear context?
- delphi - 如何在动态更新的树中使用虚拟树视图?
- java - OKHttp 响应失败:java.lang.IllegalStateException:关闭
- vuejs2 - 你能用 NuxtJS 创建一个原生的 Vue 应用吗
- docker - 在 Jenkins 管道上找不到 Docker
- c++ - 如何获得 Code::Blocks 的 C++ 代码编译器?
- javascript - 使用 jquery 构建自动完成功能时遇到问题
- android - 自定义`FloatingTitleTextInputField`在react-native中不接受TextInput的某些属性
- java - 如何根据某个字段从列表中删除重复的对象,但在删除之前添加一个数量?