Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
948 views
in Technique[技术] by (71.8m points)

unit testing - Using both Arquillian and PowerMock in the same JUnit test

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...