Debug Arquillian tests in IntelliJ

Martin Nuc picture Martin Nuc · Jul 20, 2013 · Viewed 7.9k times · Source

I have Java EE project in which I use Arquillian tests with JUnit on JBoss 7 (Windows). Tests are working fine however I cannot debug them.

From what I've googled (https://community.jboss.org/wiki/WhyDontBreakPointsWorkWhenDebugging) I understand that Arquillian tests are being run in separate VM therefore IntelliJ cannot debug them. I need IntelliJ to connect to that machine remotely over socket but I dont know how to do it.

I found this thread: Debugging with Arquillian in IntelliJ - Managed Container However I dont know how to get it work.

Also I stepped over this thread: http://devnet.jetbrains.com/message/5253623?tstart=0 so I filled hopefully appropriet surefire part in my pom.xml but it didnt help:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.3</version>
        <configuration>
            <debugForkedProcess>true</debugForkedProcess>
        <skip>false</skip>
    </configuration>
 </plugin>

Could anyone guild me please how to debug tests in such configuration?

Answer

Hardy picture Hardy · Jul 21, 2013

First of all depend on the container type you are using - managed, remote or embedded. See also https://docs.jboss.org/author/display/ARQ/Containers. For the latter the tests are running in the same JVM and you can for example debug your test directly in the IDE.

The Surefire configuration is in this case not important, because you want to debug in your IDE (unless you are executing maven goals from within your IDE).

For managed and remote containers you need to debug the actual container. For this to wrok you have to pass the right JVM options to the remote container, so that you can open a remote debugging session. One way of doing this is via arquillian.xml:

http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<!-- Need to set the default protocol and use resource filtering, because of https://issues.jboss.org/browse/ARQ-579 -->
<defaultProtocol type="Servlet 3.0"/>

<engine>
    <property name="deploymentExportPath">target/artifacts</property>
</engine>


<container qualifier="incontainer">
    <configuration>
        <property name="jbossHome">${jbossTargetDir}</property>
        <property name="javaVmArguments">-Xmx1024m -XX:MaxPermSize=512m -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</property>
        <property name="allowConnectingToRunningServer">true</property>
    </configuration>
</container>

The important part in the example above being the javaVmArguments.