Friday, May 02, 2008

Freeform projects NetBeans JUnit test results : binding output to source code

As I had mentioned in a prior post a while back, it is pretty straightforward to bind the output of a Freeform Project JUnit task to the NetBeans JUnit test results. However, there are a couple of minor tweaks that I find myself making and forgetting, so, I thought I'd drop a blog entry, even just as a reminder for myself.

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 type="xml">
<formatter usefile="false" type="brief" />
<classpath refid="whatever-path-id">

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="">\n ....
<classpath mode="compile">${test.completion.classpath}</classpath>