A lot of people have been asking about how to create JUnit Reports with their automated test cases. I’m going to show you how to create these reports in the easiest way possible. You will not have to download anything, add any code, etc. You will only have to use generate the HTML report using Ant with Eclipse.
The first think you have to do is generate the Ant build. You can do this by:
1. Right click on the project and
select Export –> Ant Buildfiles (this will be under General) –> Next–> Select the project that contains your JUnit tests –> Finish.
The default JUnit output directory is appropriately named “junit”.
2. The next thing you have to do is resolve your dependencies by making sure that the junit.jar is added to
Ant’s “Global Entries.”. You can do this by.
Window->Preferences->Ant->Runtime->Global Entries and Add External JARs… Navigate to your “eclipse” directory (where eclipse is installed). It is under “plugins” directory and presently the junit.jar is in a directory named “org.junit_3.8.1″. If this is missing then you will see error messages since
junit is an optional Ant task.
* If you are using a Mac, Preferences are under the the Eclipse menu.
3) Finally, right-click on the Ant build file build.xml (this file is the one you created in Step 1) and Run As->Ant Build. This will display a list of targets. All of the launch configurations you have previously configured will have a corresponding target in your Ant build file. Select the desired target(s), and also select the “junitreport” target (very important). Check the “Target execution order” text area to make sure the junitreport is run last.
Whenever you run a test case it will generate results and will be placed in the junit output directory. These results are formatted into an HTML report by the junitreport target and stored in the junit output directory.
As you can see below my automated Test Suite has completely run and you can see which tests failed and which passed (below). I see my cases for login, registration, and account-sign up are failing. Upon further investigation, these are failing because the web service is down on our staging server.
This is a fast and easy explanation of how to create JUnit HTML reports, but hopefully it helps get you off your feet. Next time around, we’ll have some more fun when I show you how to extend this output to get more information displayed in the report. For example to add an additional column which contains link to a screenshot taken by the test.
And happy Testing!