当 Cucumber 场景失败时,mvn test 不会失败

mvn test doesn't fail when Cucumber scenario fails

我有一个 RunCucumberTest class,如 JUnit 部分 here 中所述,还有一个 Cucumber 场景,当 运行 来自 IntelliJ 中的装订线图标时失败。

但是,为什么mvn test构建成功?

[WARNING] Tests run: 482, Failures: 0, Errors: 0, Skipped: 12
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:10 min
[INFO] Finished at: 2021-01-04T15:54:51-05:00
[INFO] ------------------------------------------------------------------------

我可以在日志中看到场景失败:

............................................F--.....................................................................................
Failed scenarios:
com/rose/sample.feature:23 # Feature name
26 Scenarios (1 failed, 25 passed)
132 Steps (1 failed, 2 skipped, 129 passed)
0m0.596s
org.junit.ComparisonFailure: expected:<x> but was:<y>

在进一步谷歌搜索后,我终于发现问题是由于我的项目中同时使用了 JUnit 和 TestNG 作为依赖项,而使用 JUnit Cucumber runner. Since I couldn't remove the JUnit and TestNG dependencies as they were inherited from a parent POM, I changed the Cucumber runner to use TestNG 而它起作用了。


后来我找到了另一个更简单的解决方案:。