issues while using @RunWith Annotation and powerMock

前端 未结 2 2104
逝去的感伤
逝去的感伤 2021-01-01 21:47

Initially I was using only Mockito in junits so I was using SpringJUnit4ClassRunner.class in @RunWith annotation ie

@RunWith(SpringJUnit4ClassRunner.class)          


        
2条回答
  •  死守一世寂寞
    2021-01-01 21:58

    You have to use the PowerMockRule.

    @RunWith(SpringJUnit4ClassRunner.class) 
    @PrepareForTest(X.class)
    public class MyTest {
        @Rule
        public PowerMockRule rule = new PowerMockRule();
    
        // Tests goes here
        ...
    }
    

    For a full example of the Spring Integration Test with PowerMock and Mockito, you could checkout this maven project.

    svn co http://powermock.googlecode.com/svn/tags/powermock-1.4.12/examples/spring-mockito/
    cd spring-mockito/
    

    Look at the dependecies to powermock.

    less pom.xml
    

    and then run the test

    mvn test
    

    and you should get the following test results :

    Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
    

提交回复
热议问题