Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

java - NoClassDefFoundError when using Powermock

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I just solved this one now, when I added the @RunWith(PowerMockRunner.class) attribute, eclipse automatically imported:

import org.powermock.modules.junit4.legacy.PowerMockRunner;

All I needed to do is change it to be:

import org.powermock.modules.junit4.PowerMockRunner;

And now it works fine with JUnit 4.8.2.

The 2nd runner is for when running with older versions of JUnit - specifically 4.3 and older.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...