Getting Started with JUnit Reports with Eclipse and Ant…

So a lot of people have been asking me 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.

As you can see I’ve specified the order in which I want my cases to run (below)

JUnit Targets

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.

Pass or Fail

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.

Happy Testing!

I have to admit…

I have to admit that I am a movie fanatic. I watch a lot of movies regularly and even give my feedback on amazon which confirms that very fact. I was watching a movie today; a movie some would consider old school (China Moon), but I couldn’t help to think that this actor is never in the tabloids or on any of the sleazy tabloid sites and he’s been such an awesome actor; which is usually a prerequisite for being in those sleeay rags. Anyway, I have to admit, I’ve never seen him play a bad role to this day.

He’s been in A Beautiful Mind, GlenGarry Glen Ross, The Truman Show, and China Moon. He’s even been in Creepshow.

He is none other than Ed Harris:

Ed Harris folks

He is the guy that shows up during your schizophrenic episode with orders from the F.B.I., while all these other schizophrenics are seeing talking purple bunnies. I’d rather get orders from Ed.