First, make sure that the JUnit task as a showoutput="true" attribute 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 usefile="false" type="brief" />
The second important part of working with the JUnit results in NetBeans is to make sure that when a test fails, 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:
- In the Project Properties UI
- In the nbproject/project.xml
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2">\n ....