问题
I've been struggling to find an obvious solution to why the linked code will not run JUnit TestRules.
I've created a success case where TestRules execute, and a failure case that shows a situation where TestRules fail.
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.
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
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
.
Does anyone have any ideas?
回答1:
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 :)
See https://github.com/cucumber/cucumber-jvm/issues/894
来源:https://stackoverflow.com/questions/34135455/why-is-my-spring-junit-test-rule-not-running