Adham
Adham

Reputation: 64904

How to run test case in JUnit from command line ?

I'm trying to run a JUnit test case from command line using this command:

F:\>java org.junit.runner.JUnitCore org.junit4.9b2.junit.SimpleTest

but I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore

Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: org.junit.runner.JUnitCore.  Program will exit.

What is the problem?

Upvotes: 2

Views: 16294

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299148

Obviously you need junit on the classpath :-)

java -cp path/to/junit.jar:path/to/local/classes org.junit.runner.JUnitCore \
         org.junit4.9b2.junit.SimpleTest

(replace the : with ; on windows platforms)

Upvotes: 8

Related Questions