我想在同一个JUnit 4测试中使用Arquillian和PowerMock的功能.
问题是两个产品都是JUnit Runners,它应该与@RunWith一起使用,这不可能在同一个测试类上使用多个@RunWith,或者将多个Runners类放在同一个@RunWith注释中.
你知道有什么办法吗
解决方法
如果您使用
PowerMockRule(这是
TestRule),则可以使用PowerMock而不使用转轮.从PowerMockRule:
Since version 1.4 it’s possible to bootstrap PowerMock using a JUnit
Rule instead of using the PowerMockRunner and the RunWith annotation.
This allows you to use other JUnit runners while still benefiting from
PowerMock’s functionality. You do this by specifying:
@RunWith(Arquillian.class); public class MyTest { @Rule PowerMockRule rule = new PowerMockRule(); // Tests goes here ... }
另请参阅Junit Parameterized tests together with Powermock – how?的答案和PowerMock谷歌组中的以下线程:Using PowerMock without the RunWith?.