rafael81 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

junit 4.12 throws Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator exception #531

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. If you use PowerMock with junit 4.12 it will throw a 
org.powermock.reflect.exceptions.FieldNotFoundException  when the test is 
starting

What version of the product are you using? On what operating system?
PowerMock 1.6.0

Please provide any additional information below.
More of the stacktrace:

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.validateTestMethods(PowerMockJUnit4MethodValidator.java:79)
    at org.powermock.modules.junit4.internal.impl.testcaseworkaround.PowerMockJUnit4MethodValidator.validateInstanceMethods(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)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:70)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.<init>(PowerMockJUnit49RunnerDelegateImpl.java:25)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:156)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
    at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)

Original issue reported on code.google.com by cheis...@squareup.com on 5 Dec 2014 at 9:07

GoogleCodeExporter commented 9 years ago
Looks like the field has been renamed to just "testClass" in JUnit 4.12.

Original comment by jrh...@gmail.com on 12 Dec 2014 at 4:15

GoogleCodeExporter commented 9 years ago
This should be changed to High priority since there is no way to run PowerMock 
with JUnit 4.12.

Original comment by nykolas....@gmail.com on 23 Dec 2014 at 6:31

GoogleCodeExporter commented 9 years ago
Also, changing to JUnit 4.11 to workaround this problem causes another problem:
org.powermock.reflect.exceptions.FieldNotFoundException: No instance field 
named "fAnnotations" could be found in the class hierarchy of 
org.junit.runner.Description.

Original comment by nykolas....@gmail.com on 23 Dec 2014 at 6:35

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 3 Jan 2015 at 8:12

GoogleCodeExporter commented 9 years ago
In https://github.com/junit-team/junit/releases, the version is 4.12-SNAPSHOT. 
Hence the fix 
static {
        if(JUnitVersion.isGreaterThanOrEqualTo("4.12")) {
            TEST_CLASS_FIELD = "testClass";
            CLASS_UNDER_TEST_FIELD = "klass";
            ERRORS_FIELD = "errors";
        }
        else {
            TEST_CLASS_FIELD = "fTestClass";
            CLASS_UNDER_TEST_FIELD = "fClass";
            ERRORS_FIELD = "fErrors";
        }
    }
doesn't apply to this version as JUnitVersion.isGreaterThanOrEqualTo("4.12") 
gives false in this case.

Original comment by reshm...@gmail.com on 11 Feb 2015 at 2:59