2011-03-13 16 views
23

PowerMockテストランナーを使用してjunitテストケースを実行しています。 私はそれを実行するには、次のコマンドラインを使用しています:NoClassDefFoundError

java -cp .:junit-4.9b2.jar:easymock-3.0.jar:powermock-easymock-1.4.8-full.jar org.junit.runner.JUnitCore SampleTest 

その際に、私はこのエラーが発生します:

initializationError(SampleTest) 
java.lang.NoClassDefFoundError: org/junit/internal/runners/TestClassRunner 
... 

私はそれを解決することができますか?

答えて

0

私はこの問題を解決しました。古いバージョンのjunit-4.0.jarを使用しました。しかし、私はまだパッケージpowermock-easymock-junit-1.4.8.zip(特にjunit-4.8.2.jar)の中で、TestClassRunnerクラスが見つからないのはなぜですか? junit-4.8.2.jarには、TestClassRunnerクラスもありません。

+0

を参照してください。私の答えを参照 – RonK

63

私は@RunWith(PowerMockRunner.class)属性、eclipseが自動的にインポート追加したとき、私はちょうど、今、これを解決:

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

を私が行うために必要なすべてのことに変更します:

import org.powermock.modules.junit4.PowerMockRunner; 

そして今JUnit 4.8.2で正常に動作します。

第2ランナーは、JUnitの古いバージョン、具体的には4.3とそれ以前のバージョンで実行している場合です。単に回避策 -

+0

答えをありがとう。 – jatanp

+0

ありがとうRonK !! – NiranjanBhat

+1

ありがとうございました。 – shafeeq

5

は、これは正しい解決策ではありませんhere

You're probably using the wrong PowerMockRunner. There's one runner made for JUnit 4.4 and above and a second runner made for JUnit 4.0-4.3 (although the latter also works for some older minor versions of JUnit 4.4).
Try switching from the org.powermock.modules.junit4.PowerMockRunner to org.powermock.modules.junit4.legacy.PowerMockRunner or vice versa. Look at the getting started guide to see how to configure this in maven.