Activating Junit tests from Command Line

Running Junit tests from command line requires two things.
1) setting your classpath.
2) invoking the junit command.

Classpath:
you’ll need the following elemements in your CLASSPATH:

* JUnit class files
* Your class files, including your JUnit test classes
* Libraries your class files depend on

Windows Example:
set CLASSPATH=%JUNIT_HOME%\junit.jar;c:\myproject\classes;c:\myproject\lib\something.jar

Unix (bash) Example:
export CLASSPATH=$JUNIT_HOME/junit.jar:/myproject/classes:/myproject/lib/something.jar

Invoking the Junit command:
java org.junit.runner.JUnitCore test class name

3) Example:
(Running SimpleJunitTest class under C:\workspace\TestProject\classes\basic)
——————————————————————————————————–
set CLASSPATH=C:\workspace\runner\thirdparty\commonLib\junit.jar;C:\workspace\TestProject\classes\basic;C:\workspace\runner\lib\JsystemCore.jar;C:\workspace\runner\thirdparty\commonLib\xalan.jar;C:\workspace\runner\thirdparty\commonLib\qdox.jar;C:\workspace\runner\thirdparty\commonLib\java2html.jar

java org.junit.runner.JUnitCore SimpleJunitTest

———————————————————————————————————-

for more info: http://junit.sourceforge.net/doc/faq/faq.htm#running_1

Fork me on GitHub