2011-11-18 22 views
1

コマンドラインから1つのJUnitテストを実行しようとしていますが、エラーが発生しています。 JUnitテストを正常にコンパイルでき、クラスファイルが正しい場所に作成されます。 しかし、私は使用してそれを実行しようとすると:コマンドラインからJUnitテストを実行中にエラーが発生しました

C:\Program Files\Java\jdk1.7.0_01\bin>java org.junit.runner.JUnitCore C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class 

を私はエラーを取得:

JUnit version 4.8.1 
Could not find class: C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\src\com\org\tests\Nav.class 
Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/SelfDesc 
ribbing 

それでは、前記存在するにもかかわらず、クラスを見つけることができない理由を私は知りませんロケーション。

答えて

2

あなたは、コマンドライン上のクラスではなく、ファイル名の名前を指定する必要があります。JUnitCoreのjavadocから

java org.junit.runner.JUnitCore com.org.tests.Nav 

を:

JUnitCore is a facade for running tests. It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures. To run tests from the command line, run java org.junit.runner.JUnitCore TestClass1 TestClass2 .... For one-shot test runs, use the static method runClasses(Class[]). If you want to add special listeners, create an instance of org.junit.runner.JUnitCore first and use it to run the tests.

、あなたはbinを追加する必要がありますディレクトリ(srcではないことに注意)をコマンドラインのクラスパスに追加します。これは次のようになります。

java -cp C:\eclipse\eclipse-java-helios-SR1-win32\eclipse\JunitWS\SeleniumTraining\bin org.junit.runner.JUnitCore com.org.tests.Nav 
+0

ありがとうございました。私はあなたが甘やかされたように道を変えました、そして、今それはうまく働いています。どうもありがとう 。 –

関連する問題