Possible Duplicate:
How to run Junit testcases from command line?
I've run my JUnit tests using maven before. Now I'm packaging all my source code into a JAR file, and want to run it using a java command. How can I do that? Note that there is no main class in my code.
The easiest (as in least amount of new code required) way to do this is to run the test as a parametrized test (annotate with an @RunWith(Parameterized. class) and add a method to provide 10 empty parameters). That way the framework will run the test 10 times.
You can run JUnit tests from the command line using the JUnit core class of the JUnit framework. The org. junit. runner.
You need to make sure the classpath contains
You can set the class path by using the -cp flag to the java command. Then you can use junit.textui.TestRunner to run the tests.
If you're using Linux (note the use of : as the path separator between jars)
java -cp /path/to/my.jar:/path/to/junit.jar junit.textui.TestRunner com.mypackage.MyClassWithUnitTests
If you're using Windows (note the use of ; as the path separator between jars)
java -cp /path/to/my.jar;/path/to/junit.jar junit.textui.TestRunner com.mypackage.MyClassWithUnitTests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With