简体   繁体   English

为什么我的Spring JUnit测试规则未运行?

[英]Why is my Spring JUnit Test Rule not running?

I've been struggling to find an obvious solution to why the linked code will not run JUnit TestRules. 我一直在努力寻找一个显而易见的解决方案,以解决为什么链接的代码无法运行JUnit TestRules的问题。

I've created a success case where TestRules execute, and a failure case that shows a situation where TestRules fail. 我创建了一个成功的案例 ,其中执行了TestRules,一个失败案例 ,显示了TestRules失败的情况。

Is anybody able to see why the TestRules are not being picked up? 有人能看到为什么没有提取TestRules吗? It's not just Spring's TestRule not being picked up. 不只是Spring的TestRule没有被使用。 It seems to be all TestRules, as demonstrated by MyTestRule.java in the source code. 如MyTestRule.java在源代码中所示,这似乎是所有TestRules。

Running mvn clean install on the success case, will see all tests passing. 在成功案例中运行mvn clean install ,将看到所有测试通过。 However running mvn clean install on the failure case will produce the following failure: 但是,在故障情况下运行mvn clean install将产生以下故障:

    Tests run: 13, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.9 sec <<< FAILURE! - in net.serenitybdd.demos.acceptance.CalculateResults
net.serenitybdd.demos.acceptance.CalculateResults  Time elapsed: 1.454 sec  <<< FAILURE!
java.lang.AssertionError: expected:<3> but was:<1>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:743)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:555)
        at org.junit.Assert.assertEquals(Assert.java:542)
        at net.serenitybdd.demos.acceptance.CalculateResults.test(CalculateResults.java:60)


Results :

Failed tests:
  CalculateResults.test:60 expected:<3> but was:<1>

Tests run: 13, Failures: 1, Errors: 0, Skipped: 0

This is a result of Spring's SpringMethodRule not being picked up, which can be seen in the test class net.serenitybdd.demos.acceptance.CalculateResults . 这是由于Spring的SpringMethodRule没有被拾取的结果,可以在测试类net.serenitybdd.demos.acceptance.CalculateResults

Does anyone have any ideas? 有人有什么想法吗?

It seems I'm using Cucumber with Serenity and the Cucumber team is not currently supporting JUnit TestRules for philosophical reasons. 看来我在使用带有Serenity的Cucumber,并且出于哲学原因,Cucumber团队当前不支持JUnit TestRules。 Here's hoping they change their mind :) 希望他们能改变主意:)

See https://github.com/cucumber/cucumber-jvm/issues/894 参见https://github.com/cucumber/cucumber-jvm/issues/894

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM