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- powermock-api-mockito-common-1.6.5.jar
- objenesis-2.2.jar
- powermock-mockito-1.6.5-full.jar
- mockito-core-1.10.19.jar
- javassist-3.20.0-GA.jar
- hamcrest-core-1.3.jar
- 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
Post a Comment