Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit run tests command line

Tags:

java

junit

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.

like image 713
Alex Avatar asked Oct 30 '12 19:10

Alex


2 Answers

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
like image 158
Guido Simone Avatar answered Sep 30 '22 02:09

Guido Simone


The classpath should be semi colon separated (on Windows - not sure what you are using.)

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

Also with this command line you will need to run it in your project root

like image 36
RNJ Avatar answered Sep 30 '22 02:09

RNJ