Questo sito è ancora in costruzione.
L'attuale sito ufficiale del JUG Padova è all'indirizzo www.jugpadova.it

Debugging tests of a Maven project in NetBeans

Occasionally I experienced some problems in debugging test classes using NetBeans with Maven projects. Simply, the debugger started but didn’t attach to the running tests.

Eventually I discovered the reason!

I used to configure the surefire plugin with:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <skip>false</skip>
    <useFile>true</useFile>
    <forkMode>once</forkMode> <!-- always, once or never -->

    <!-- <reportFormat>plain</reportFormat> -->

    <argLine>-Xmx512M</argLine>
  </configuration>
</plugin>

The problem is the argLine parameter. It will override the parameters the Mevenide plugin will pass for debugging tests. So, I commented it in my configuration:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <skip>false</skip>
    <useFile>true</useFile>
    <forkMode>once</forkMode> <!-- always, once or never -->

    <!-- <reportFormat>plain</reportFormat> -->
    <!--argLine>-Xmx512M</argLine-->
    <!-- don't use if you want to debug tests in NetBeans -->

  </configuration>
</plugin>

…and now I can debug my tests!