Debug Arquillian tests in IntelliJ
Asked Answered
S

2

9

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?

Sieracki answered 20/7, 2013 at 18:33 Comment(0)
S
8

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.

Solvable answered 21/7, 2013 at 9:50 Comment(3)
I use Managed container. I tried to play with your suggestion but when start debugging i see in console: Listening for transport dt_socket at address: 5005 and nothing more happens. I found out that its because of susspend=y parameter. I guess now I should let IntelliJ connect to debug session but I dont know how to do it.Sieracki
Finally I could debug my test. I used mvn test -Parq-jbossas-managed to run JBoss VM and then I used remote profile in IntelliJ to connect to that VM. Is it possible to make it automatically in Intellij? I mean running mvn test before connecting?Sieracki
Me also would like to know how to Debug Arquillian test like a simple Unit test from the Idea IDEMedeiros
C
3

I can run Arqullian tests by either Maven or by IntelliJ. I use embedded container. The most important thing is to configure the JBoss home at arqullian.xml nor just at the Maven configuration to IntelliJ know where the JBoss home is.

<arquillian xmlns="http://jboss.org/schema/arquillian"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://jboss.org/schema/arquillian
    http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

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

<container qualifier="jbossas-managed" default="true">
    <configuration>

        <!-- JBoss embedded does not use this property
        <property name="javaVmArguments">-java.util.logging.manager=org.jboss.logmanager.LogManager -Xmx512m -XX:MaxPermSize=256m -Djava.util.logging.manager=org.jboss.logmanager.LogManager</property>
        -->

        <property name="jbossHome">target/wildfly-8.1.0.Final</property>
        <property name="modulePath">target/wildfly-8.1.0.Final/modules</property>
        <property name="allowConnectingToRunningServer">true</property>
    </configuration>
</container>

IMPORTANT for debugging and running test in IntelliJ:

From some reason you must specify the logging manager to be able run embedded JBoss. For Maven it is easy and you can set it to configuration:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <!-- Fork every test because it will launch a separate AS instance -->
                <forkMode>always</forkMode>
                <systemPropertyVariables>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                </systemPropertyVariables>
                <redirectTestOutputToFile>false</redirectTestOutputToFile>
            </configuration>
        </plugin>

But the IntelliJ does not care about these plugin configuration at Maven and you must set it directly at the test case configuration. I did not find better solution. The embedded container does not care about Java VM configuration in arqullian.xml.

IntelliJ Arequllian test configuration

Here is always possibility to debug throught remote debugging. I like to do it at IDE. For me it is more confortable way. When you want to enable remote debugging you must set configuration to JAVA_OPT for embedded container nor at arqullian.xml.

Coel answered 20/11, 2015 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.