【问题标题】:Debug Arquillian tests in IntelliJ在 IntelliJ 中调试 Arquillian 测试
【发布时间】:2013-07-20 18:33:27
【问题描述】:

我有一个 Java EE 项目,我在 JBoss 7 (Windows) 上使用带有 JUnit 的 Arquillian 测试。测试工作正常,但我无法调试它们。

根据我在谷歌上搜索到的内容 (https://community.jboss.org/wiki/WhyDontBreakPointsWorkWhenDebugging),我了解到 Arquillian 测试是在单独的 VM 中运行的,因此 IntelliJ 无法调试它们。我需要 IntelliJ 通过套接字远程连接到那台机器,但我不知道该怎么做。

我找到了这个帖子:Debugging with Arquillian in IntelliJ - Managed Container 但是我不知道如何让它工作。

我也跳过了这个线程:http://devnet.jetbrains.com/message/5253623?tstart=0 所以我希望在我的 pom.xml 中填写适当的肯定部分,但它没有帮助:

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

谁能指导我如何在这种配置中调试测试?

【问题讨论】:

    标签: java unit-testing junit jboss7.x jboss-arquillian


    【解决方案1】:

    首先取决于您使用的容器类型 - 托管、远程或嵌入式。另见https://docs.jboss.org/author/display/ARQ/Containers。对于后者,测试在同一个 JVM 中运行,例如,您可以直接在 IDE 中调试您的测试。

    在这种情况下,Surefire 配置并不重要,因为您想在 IDE 中进行调试(除非您在 IDE 中执行 maven 目标)。

    对于托管容器和远程容器,您需要调试实际容器。为此,您必须将正确的 JVM 选项传递给远程容器,以便您可以打开远程调试会话。一种方法是通过 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>
    

    上面示例中的重要部分是 javaVmArguments

    【讨论】:

    • 我使用托管容器。我尝试按照您的建议进行操作,但是当开始调试时,我在控制台中看到:Listening for transport dt_socket at address: 5005 并且没有任何反应。我发现这是因为susspend=y 参数。我想现在我应该让 IntelliJ 连接到调试会话,但我不知道该怎么做。
    • 终于可以调试我的测试了。我使用mvn test -Parq-jbossas-managed 运行 JBoss VM,然后使用 IntelliJ 中的远程配置文件连接到该 VM。是否可以在 Intellij 中自动实现?我的意思是在连接之前运行mvn test
    • 我也想知道如何调试 Arquillian 测试,就像来自 Idea IDE 的简单单元测试一样
    【解决方案2】:

    我可以通过 Maven 或 IntelliJ 运行 Arqullian 测试。我使用嵌入式容器。最重要的是在 arqullian.xml 中配置 JBoss home,而不仅仅是在 Maven 配置中让 IntelliJ 知道 JBoss home 在哪里。

    <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>
    

    在 IntelliJ 中调试和运行测试的重要提示:

    出于某种原因,您必须指定日志管理器才能运行嵌入式 JBoss。对于 Maven,这很容易,您可以将其设置为配置:

    <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>
    

    但是 IntelliJ 并不关心 Maven 中的这些插件配置,您必须直接在测试用例配置中进行设置。我没有找到更好的解决方案。嵌入式容器不关心 arqullian.xml 中的 Java VM 配置。

    这里总是有可能通过远程调试进行调试。我喜欢在 IDE 做这件事。对我来说,这是更舒适的方式。当您想要启用远程调试时,您必须为嵌入式容器或 arqullian.xml 设置配置为 JAVA_OPT。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-19
      • 2022-01-02
      • 2014-09-27
      • 1970-01-01
      • 2015-02-26
      • 2014-06-16
      • 2013-03-03
      • 1970-01-01
      相关资源
      最近更新 更多