Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to export (JUnit) test suite as executable jar

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.

like image 834
kostja Avatar asked Jan 10 '11 15:01

kostja


People also ask

How do I export an executable JAR file from Eclipse?

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.

How do I run a jar file from JUnit?

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.

How do I export JUnit results from Eclipse?

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.


1 Answers

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");             } 
like image 171
Jeanne Boyarsky Avatar answered Sep 23 '22 18:09

Jeanne Boyarsky