I have a Gradle based Java project, now I want to mock my personal method using PowerMock. The problem is that I cannot use PowerMockRunner, since I always get the following exception when I add @RunWith(org.powermock.modules.junit4.PowerMockRunner.class) annotation @RunWith(org.powermock.modules.junit4.PowerMockRunner.class) .
Mistake:
org.powermock.reflect.exceptions.FieldNotFoundException: Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator. at org.powermock.reflect.internal.WhiteboxImpl.getInternalState(WhiteboxImpl.java:581) at org.powermock.reflect.Whitebox.getInternalState(Whitebox.java:308) at org.powermock.modules.junit4.internal.impl.testcaseworkaround.PowerMockJUnit4MethodValidator.validate TestMethods(PowerMockJUnit4MethodValidator.java:79) at org.powermock.modules.junit4.internal.impl.testcaseworkaround.PowerMockJUnit4MethodValidator.validate InstanceMethods(PowerMockJUnit4MethodValidator.java:49) at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:51) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:108) ...
These are my test dependencies:
testCompile 'junit:junit:4.+', 'org.powermock:powermock-core:1.5.6', 'org.powermock:powermock-module-junit4:1.5.6', 'org.powermock:powermock-api-mockito:1.5.6'
The test itself also fails when it is completely empty (initialization error):
@RunWith(PowerMockRunner.class) public class SomeTest { @Test public void testSomething() { } }
Any ideas what could be wrong? Other tests using PowerMock work fine (none of them use PowerMockRunner).
Greetings and thanks for any help! Ben
java exception junit powermock
Ben 04 Oct '14 at 12:41 2014-10-04 12:41
source share