I'm running a junit
test case using the PowerMock
test runner.
I'm using the following command line to execute it:
java -cp .:junit-4.9b2.jar:easymock-3.0.jar:powermock-easymock-1.4.8-full.jar org.junit.runner.JUnitCore SampleTest
When doing so I am receiving this error:
initializationError(SampleTest)
java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner
...
How can I fix it?
I am using JUnit 4.0 - 4.3 and I updated my maven dependency to use powermockito 2.0.0-beta.5 version. It just started working.
This Exception occurs when you Import the legacy version of PowerMockRunner.class when using JUnit 4.X or higher version since this legacy class is not available to run when using it with @RunWith annotation. I have solved this issue by replacing older legacy version import with the new version.
Incorrect Import:
Correct Import:
I solved the problem. I used old version junit-4.0.jar. But I still don't understand why is missing the class TestClassRunner especially in the package powermock-easymock-junit-1.4.8.zip (there is junit-4.8.2.jar)? The junit-4.8.2.jar is missing the class TestClassRunner also.
See here
I just solved this one now, when I added the
@RunWith(PowerMockRunner.class)
attribute,eclipse
automatically imported:All I needed to do is change it to be:
And now it works fine with
JUnit 4.8.2
.The 2nd runner is for when running with older versions of
JUnit
- specifically4.3
and older.