Bug in Ant’s JUnitReport task – ‘Properties’ link in the HTML report is broken

This post explains the root cause and solutions for a bug 51049 in Ant’s JUnitReport task. Due to this bug, the ‘Properties’ link in the JUnit HTML report is broken; clicking on this link either leads to an error message or the page does not show any properties.

I came across this bug when I was generating JUnit report using Eclipse Ant plug-in. I was using Eclipse Indigo (version 3.7.2) with Apache Ant 1.8.2 plug-in. The JUnitReport task generated the HTML report successfully. This HTML report contains a link named ‘Properties’ which displays the system properties for a particular test run. In my case, when the ‘Properties’ link was clicked, the page did not display any properties; it was a blank page.

To find the root cause, I used the Web Developer tools provided by Firefox browser. (I was using Firefox 17.0.1). After the ‘Properties’ link was clicked, I went to Firefox -> Menu -> Tools -> Web Developer -> Error Console. The ‘Error’ tab showed the error ‘unterminated string literal’:


This problem is already reported on Ant Bugzilla (link).

When I used Ant 1.8.4 (by changing the Ant Home directory in the Eclipse’s Run Configuration), the problem was fixed and the ‘Properties’ linked showed the properties correctly.

When I compared the HTML reports generated by the two Ant versions, following difference was observed:

HTML report created by Ant 1.8.2:

cur[‘line.separator’] = ‘

HTML report created by Ant 1.8.4:

cur[‘line.separator’] = ‘\r\n’;

JUnitReport task first creates an XML which consolidates all the test results in one XML and then applies XSL transformation on that XML to generate the HTML report. Out of the box, Ant (1.8.2 and 1.8.4) provides two XSL files – junit-frames.xsl and junit-noframes.xsl. We can instruct the JUnitReport task to use one of these XSLs through /junitreport/report@format attribute of the Ant task. I was using junit-noframes.xsl for which the Ant target looked like this:

<target name=”gen_reports”>
<junitreport todir=”${junit.tests.reports.dir}”>
<fileset dir=”${junit.tests.reports.dir}” includes=”TEST-*.xml”/>
<report todir=”${junit.tests.reports.dir}” format=”noframes“/>

When I compared junit-noframes.xsl of Ant 1.8.2 with that of Ant 1.8.4, following differences were observed:

Ant 1.8.2


Ant 1.8.4


The change in Ant 1.8.4 is that it replaces ASCII characters 10 and 13 with ‘\n’ and ‘\r’ respectively. In ASCII, 10 represents a Line Feed (LF) character and 13 represents a Carriage Return (CR) character. (Reference: http://www.asciitable.com/). Thus, the change in Ant 1.8.4 is to replace Line Feed and Carriage Return characters in the XML with ‘\n’ and ‘\r’ characters respectively in the HTML. This change fixes the problem of ‘unterminated string literal’ and the ‘Properties’ link in the HTML report starts working as expected.

To summarize, some of the solutions to this problem are:

1. Use Ant 1.8.3 or 1.8.4. Ant 1.8.4 contains the bug fix. The release notes mention that the fix is available in Ant 1.8.3 also.

2. Or, use a custom XSL for creating the JUnit report. For more information about this, see the example listed here.

After working around this problem, I had a better understanding of how Ant generates JUnit reports. I believe that this post will help other developers also.

This entry was posted in Ant, JUnit and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s