简体   繁体   中英

Java JUnit Test Cannot Find Class

I am trying to run a Test Class that I have created in IntelliJ. When I run it in IntelliJ the test passes. However, I want to be able to script it so I am trying to run the test via commandLine.

I am running the following command from this directory: $PROJECT_HOME/output/test/com/proj1/ome

java -cp .:$PROJECT_HOME/tools/junit4.11.jar:$PROJECT_HOME/tools/hamcrest-all-1.3.jar org.junit.runner.JUnitCore ClassATest

It gives me the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: ClassATest (wrong name: com/proj1/ome/ClassATest)

I read that this is because you cannot run the project from within the package. So I went down to the bottom level (recommended by the Stack Overflow post I read) and tried it from there. So now I was running the following commands from this directory: $PROJECT_HOME/output/test/com

java -cp .:/$PROJECT_HOME/tools/junit4.11.jar:$PROJECT_HOME/tools/hamcrest-all-1.3.jar org.junit.runner.JUnitCore ClassATest
java -cp .:/$PROJECT_HOME/tools/junit4.11.jar:$PROJECT_HOME/tools/hamcrest-all-1.3.jar org.junit.runner.JUnitCore proj1/ome/ClassATest

These gave me the following output

JUnit version 4.11
Could not find class: ClassATest

Time: 0.001

OK (0 tests)

I then tried going down one more directory and tried it again but got the same results.

Any ideas on where I am going wrong would be greatly appreciated.

Thanks

You should be in your $PROJECT_HOME/output/test directory. Then run:

java -cp .:/$PROJECT_HOME/tools/junit4.11.jar:$PROJECT_HOME/tools/hamcrest-all-1.3.jar org.junit.runner.JUnitCore com.proj1.ome.ClassATest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM