本文介绍了为什么我的Spring JUnit测试规则未运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找一个显而易见的解决方案,以解决为什么链接的代码无法运行JUnit TestRules的问题.

I've been struggling to find an obvious solution to why the linked code will not run JUnit TestRules.

我创建了一个成功案例,其中执行了TestRules,并且失败案例,其中显示了TestRules失败的情况.

I've created a success case where TestRules execute, and a failure case that shows a situation where TestRules fail.

有人能看到为什么没有拿起TestRules吗?不只是Spring的TestRule没有被使用.正如MyTestRule.java在源代码中所展示的,这似乎就是所有TestRules.

Is anybody able to see why the TestRules are not being picked up? It's not just Spring's TestRule not being picked up. It seems to be all TestRules, as demonstrated by MyTestRule.java in the source code.

在成功案例中运行mvn clean install,将看到所有测试通过.但是,在故障情况下运行mvn clean install会产生以下故障:

Running mvn clean install on the success case, will see all tests passing. However running mvn clean install on the failure case will produce the following failure:

    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

这是Spring的 SpringMethodRule 未获取,可以在测试类net.serenitybdd.demos.acceptance.CalculateResults中看到.

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.

有人有什么想法吗?

推荐答案

似乎我正在使用带有Serenity的Cucumber,并且出于哲学原因,Cucumber团队当前不支持JUnit TestRules.希望他们能改变主意:)

It seems I'm using Cucumber with Serenity and the Cucumber team is not currently supporting JUnit TestRules for philosophical reasons. Here's hoping they change their mind :)

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

这篇关于为什么我的Spring JUnit测试规则未运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:39