Is there a way in eclipse (Helios) to package/export my JUnit test suites (or maybe even test cases if possible) as executable jars?
I know how to generate runnable jars from projects with a main class, but i'm clueless about how to include a TestRunner
.
Is there a straightforward way, or do I have to make a workaround main class calling the TestRunner
somehow?
Details would be great.
To export your project, right-click it and select Export. Select Java > Runnable JAR file as the export destination and click Next. On the next page, specify the name and path of the JAR file to create and select the Launch configuration that includes the project name and the name of the test class.
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.
In the top right corner of the Junit test runner, you can see a dropdown. Click that and you will find an option to export. Export the test result to the desired location. You will get the XML format of the test report in the provided location.
You are correct that a main() method is needed for an executable jar.
It's easy to add a main method to your test suite though.
public static void main(String[] args) throws Exception { JUnitCore.main( "com.stackoverflow.MyTestSuite"); }
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