Could not find or load the main class org.junit.runner.JUnitCore

I have packaged test classes in a JAR. I have junit-4.10.jar and aJar.jar in the same folder. When I try to execute:

 java -cp .:junit-4.10.jar org.junit.runner.JUnitCore TestOne Error: Could not find or load main class org.junit.runner.JUnitCore 

How to make it work?

When I type: java aJar.jar:junit-4.10.jar org.junit.runner.JUnitCore TestOne

I get

 Error: Could not find or load main class aJar.jar:junit-4.10.jar 
+7
source share
2 answers

You seem to be running on Windows, not Linux / UNIX. Windows path separator is ; , not : In addition, you did not put the JAR file in the classpath. So what do you want:

 java -cp aJar.jar;junit-4.10.jar org.junit.runner.JUnitCore TestOne 

This, of course, assumes that both jars are in the current directory. You should also always avoid putting classes in the default package.

+6
source

I recently had the same problem (JUnit 4.12) and managed to solve it (Windows) with the following command:

 java -cp "<libs>;<relative path to .class project folder>" org.junit.runner.JUnitCore <package.ClassName> 

Import to notice "" in the class path declaration and split by ";"

0
source

Source: https://habr.com/ru/post/1212363/


All Articles