JUnit run tests command line

java, junit

Solution

Assuming this is Linux/Mac (not Windows) and your path separator is correct (:), since your test class files exist in package subdirectories under the current working directory (.) You need to add "." to your class path, for example:

java -cp .:build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester

Problem

I've got the following structure ``` lib/junit-4.10.jar tests/Tester.java tests/Tester.class build/jar/jar_file.jar ``` (Tester belongs to package tests) I can compile tests using ``` javac -cp build/jar/jar_file.jar:lib/junit-4.10.jar tests/*.java ``` However I can't seem to run tests: ``` java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore tests.Tester ``` or ``` java -cp build/jar/jar_file.jar:lib/junit-4.10.jar org.junit.runner.JUnitCore Tester ``` And I get the following output: ``` JUnit version 4.10 Could not find class: tests.Tester Time: 0.001 OK (0 tests) ``` How do I resolve this `Could not find class` problem? I think it may be classpath related.

Original source