How to run external testcase(Class,junit) in java program?
You could put that code in a utility method in a common class, and invoke the common code in both tests. use case: your app/framework supports several databases. so you have one base test class which contains tests for all features and one extension per database which creates the connection, loads the initial DDL/data.
To start them in your IDE go to the test class, e.g. TestJunit , right-click, and select run as JUnit Test (or similar).
In order to run all of the tests in a directory including tests in nested directories you will need to use something like googlecode. junittool box. Right clicking on this class and selecting Run As JUnit test runs all of the tests in the specified directory including all tests in nested subfolders.
If you want to run JUnit tests through a Java program, you could use the JUnitCore class
JUnitCore is a facade for running tests.
It supports running JUnit 4 tests, JUnit 3.8.x tests, and mixtures.
To run tests from the command line, run:
(windows)
java -cp /path/to/junit.jar;/path/to/yourTextClasses org.junit.runner.JUnitCore TestClass1 TestClass2 ....
(Unix)
java -cp /path/to/junit.jar:/path/to/yourTextClasses org.junit.runner.JUnitCore TestClass1 TestClass2 ....
For one-shot test runs, use the static method
runClasses(Class[])
.
Make sure you have junit.jar in your classpath, and the jar or classes of your external tests also in the the classpath.
That way you can execute them from the command-line (which may not be what you are after) or directly within your java program.
JUnitCore.runClasses(TestClass1,TestClass2,...)
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