简体   繁体   中英

Debug Arquillian tests in IntelliJ

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?

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 .

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测试配置

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM