Reputation: 1507
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
Upvotes: 1
Views: 2314
Reputation: 15199
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
Upvotes: 2