我想在同一JUnit 4测试中同时使用Arquillian和PowerMock的功能.
I would like to use the features of both Arquillian and PowerMock in the same JUnit 4 test.
问题是两个产品都是JUnit Runner,应与@RunWith一起使用,并且不可能在同一测试类上使用多个@RunWith或将多个Runner放在同一个类中在同一@RunWith注释中.
The problem is that both products are JUnit Runners which should be used with @RunWith, and this is not possible to use multiple @RunWith on the same test class, or to put multiple Runners class in the same @RunWith annotation.
你知道有什么办法吗?
推荐答案如果使用 PowerMockRule (这是 TestRule ).在PowerMockRule中:
You can use PowerMock without using the runner if you use the PowerMockRule (which is a TestRule). From the PowerMockRule:
从1.4版开始,可以使用JUnit引导PowerMock 规则而不是使用PowerMockRunner和RunWith注释. 这使您可以使用其他JUnit运行器,同时仍能从中受益 PowerMock的功能.您可以通过指定:
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 ... }
另请参阅与Powermock一起进行Junit参数化测试的答案-如何?以及PowerMock谷歌组中的以下线程:使用PowerMock而不使用RunWith?.
See also the answers to Junit Parameterized tests together with Powermock - how? and the following thread in the PowerMock google group: Using PowerMock without the RunWith?.
更多推荐
在同一JUnit测试中同时使用Arquillian和PowerMock
发布评论