It should also be noted that the original version of this entry came from my blog entry at Freeform Project JUnit Results
The JUnit task needs to have an attribute showoutput="true" and has a formatter that explicitly states that doesn't use a file, e.g.
<formatter usefile="false" type="brief"/>
Emphasis on not using a file : e.g. you can use an xml formatter and it would work; however, if you don't specify the usefile="false" attribute, everything goes to the file and NetBeans doesn't get a chance to capture the output and display the results in a nice JUnit test results tree. As a result, the best combination ends up being a combination of a xml formatter that outputs to a file, and a brief formatter that doesn't, e.g. :
<junit fork="yes" printsummary="withOutAndErr" showoutput="true" errorProperty="test.failed"
failureProperty="test.failed" filtertrace="false">
<formatter type="xml">
<formatter usefile="false" type="brief" />
<classpath refid="whatever-path-id" />
</junit>
When you click on the failure in the JUnit results, you want NetBeans to take you to the right line in the source code:
![]() |
In order to accomplish that, make sure that you properly set the output directory for your test cases in your NetBeans project with the UI or project.xml:
![]() |
...
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2">\n ....
<compilation-unit>
<package-root>test/integration</package-root>
<unit-tests/>
<classpath mode="compile">${test.completion.classpath}</classpath>
<built-to>dest/test/unit</built-to>
<source-level>1.5</source-level>
</compilation-unit>
....
</java-data>
....
| junit_output_project_props.png | ![]() |
39286 bytes |
| netbeans_junit_beauty.png | ![]() |
20129 bytes |