1

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

1
  • 4
    Use the fully qualified class name com.proj1.ome.ClassATest. Commented Nov 19, 2013 at 21:58

1 Answer 1

2

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
2
  • should be com.proj1.ome.ClassATest (You forgot the ome)
    – Taylor
    Commented Nov 19, 2013 at 22:02
  • Works perfectly, thanks a ton! Can't believe I didn't think to use . instead of /. Such a simple miss.
    – dev
    Commented Nov 20, 2013 at 0:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.