play1 icon indicating copy to clipboard operation
play1 copied to clipboard

PowerMock support

Open JorgeJOcampo opened this issue 7 years ago • 1 comments

I try to test with PowerMock with these dependencies:

- org.mockito -> mockito-core 2.23.4
- org.powermock -> powermock-module-junit4 1.7.4
- org.powermock -> powermock-core 1.7.4
- org.powermock -> powermock-api-mockito2 1.7.4

and this code:

@RunWith(PowerMockRunner.class)
public class ContextProcessorUtilsTest extends UnitTest{
    @Test
    @PrepareOnlyThisForTest(ContextProcessorUtils.class)
    public void getSessionTriggers() {
        PowerMockito.mockStatic(ContextProcessorUtils.class);
    }
}

and this:

@RunWith(PowerMockRunner.class)
@PrepareForTest(ContextProcessorUtils.class)    
public class ContextProcessorUtilsTest extends UnitTest{
    @Test
    public void getSessionTriggers() {
        PowerMockito.mockStatic(ContextProcessorUtils.class);
    }
}

and the error: A java.lang.ClassNotFoundException has been caught, utils.ContextProcessorUtilsTest

JorgeJOcampo avatar Dec 12 '18 14:12 JorgeJOcampo

@JorgeJOcampo Can you share the full stack trace?

P.S. Using PowerMock is a bad practice (in my opinion). Prefer to avoid using static methods in your code.

asolntsev avatar Dec 12 '18 21:12 asolntsev