Using both Arquillian and PowerMock in the same JUnit test

后端 未结 3 564
难免孤独
难免孤独 2020-12-20 14:48

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 sh

3条回答
  •  渐次进展
    2020-12-20 15:50

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

提交回复
热议问题