issues while using @RunWith Annotation and powerMock
java, junit, mockito, powermock
Solution
I know this thread is old, but it's good to add that since 2014 and this pull request, you can use the `@PowerMockRunnerDelegate` annotation to "delegate" the run context to `SpringJUnit4ClassRunner` (or any other runner really).
Above code would look like :
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@PrepareForTest(X.class);
public class MyTest {
// Tests goes here
...
}
With this annotation, you don't need the PowerMock rule anymore !
Problem
Initially I was using only Mockito in junits so I was using SpringJUnit4ClassRunner.class in @RunWith annotation ie ``` @RunWith(SpringJUnit4ClassRunner.class) ``` due to which spring dependency injection was working fine and was getting a bean through ``` @Autowired Someservice someservice ; ``` But now, I have also integrated PowerMock in it. So as per doc , I have replaced class mentioned in @RunWith annotation with ``` @RunWith(PowerMockRunner.class) ``` but now, someservice is coming out to be null. Is there a way to use both SpringJUnit4ClassRunner.class and PowerMockRunner.class in @RunWith annotation