PowerMock Setup

JAR's

The following JAR's need to be included in your Java project's buildpath in order for PowerMock to work properly with JUnit tests.

Download link: https://github.com/jayway/powermock/wiki/Downloads
  1. powermock-api-mockito-common-1.6.5.jar
  2. objenesis-2.2.jar
  3. powermock-mockito-1.6.5-full.jar
  4. mockito-core-1.10.19.jar
  5. javassist-3.20.0-GA.jar
  6. hamcrest-core-1.3.jar
  7. junit-4.12.jar

JUnit test class

The following lines of code need to be included in JUnit test classes to add PowerMock functionality.
 
1|    import org.powermock.core.classloader.annotations.PrepareForTest;
2|    import org.powermock.modules.junit4.PowerMockRunner;
3|
4|    @PrepareForTest(ChildClass.class)
5|    @RunWith(PowerMockRunner.class)
6|    public class ClassTest {
7|    ...
8|    }

In most cases the class under test needs to be included as a parameter in the @PrepareForTest annotation. PowerMockRunner.class must always be included within the @RunWith annotation when using PowerMock, unless a custom Test Runner is needed.

Comments

Popular posts from this blog

Mocking Super Class Method Invocations with PowerMock

Verifying Static Method Calls

Unit Testing a Singleton Using PowerMock