我想在同一JUnit 4测试中使用Arquillian和PowerMock的功能。
问题在于这两个产品都是JUnit Runner
,应与@RunWith
一起使用,并且不可能在同一个测试类上使用多个@RunWith
,或者在同一个Runner
批注中放置多个@RunWith
s类。
你知道有什么办法吗?
最佳答案
如果使用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?。
关于unit-testing - 在同一JUnit测试中同时使用Arquillian和PowerMock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9496552/