Using both Arquillian and PowerMock in the same JUnit test

爷,独闯天下 提交于 2019-11-28 07:22:37

问题


I would like to use the features of both Arquillian and PowerMock in the same JUnit 4 test.

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.

Do you know any way to do that ?


回答1:


You can use PowerMock without using the runner if you use the PowerMockRule (which is a TestRule). From the 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
    ...
}

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?.




回答2:


No, you either need to:

  • use one and create a test base class that does the things you wanted the other runner to do.
  • separate your test into multiple tests, each using different runners.



回答3:


JUnit4 only supports one @RunWith annotation, and JUnit4's @RunWith annotation doesn’t accept multiple runners.

Reference: project13



来源:https://stackoverflow.com/questions/9496552/using-both-arquillian-and-powermock-in-the-same-junit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!