在 IntelliJ 中,我如何调试 Maven 测试目标?

问题描述 投票:0回答:8

使用 intellij 和 maven pom 文件,我如何调试在 maven 测试目标内运行的测试?

当我直接在代码中运行它们时,它会抱怨缺少配置文件,我已经在 intellij 的 Maven 项目中勾选了它。

testing maven-2 intellij-idea
8个回答
220
投票

http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html

  • 什么时候surefire插件版本< 2.14: use
    -DforkMode=never
  • 当 surefire 插件版本 >= 2.14 时:使用
    -DforkCount=0

在 IDEA 中,打开您的运行/调试配置,在

Runner
选项卡中,添加 fork 选项
-DforkCount=0


33
投票

我使用以下选项执行测试:

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=6666 -Xnoagent -Djava.compiler=NONE" test

...然后使用远程调试器连接到 Maven。


27
投票

-DforkMode=never
不再起作用,它现在已在 SureFire 中弃用。

使用 surefire 插件 2.14+ 时使用

-DforkCount=0
代替。


26
投票

右键单击您的目标并“调试[您的目标]”(在您的情况下是测试目标)怎么样?

debug goal


10
投票

问题已回答。但只是分享我自己的经验。 选择的答案没有解决我的问题。 我的代码有多个模块。

foolshat 的回复确实为我的问题带来了宝贵的见解。

我有两个解决方案, 1. 使用您的 IDEA,通过添加 VM 选项

-DforkMode=never
;必须以调试模式运行它。 2.设置远程调试,指定套接字,在这种情况下不需要forkMode。

这只是我所经历的总结。


2
投票

mvn 干净验证-DforkCount=0 使用 surefire 插件时


1
投票

Colin Hebert 的解决方案对我也不起作用。但幸运的是,我找到了一种调试测试的简单方法,方法是右键单击测试方法旁边出现的绿色三角形:

Java test class example

希望对你有帮助!


-2
投票

我已经尝试了所有 -DforkCount=0、-DforkMode=never 等。但我仍然无法调试代码。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>3.0.0-M5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <parallel>methods</parallel>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                        <reuseForks>false</reuseForks>
                        <trimStackTrace>false</trimStackTrace>
                        <systemPropertyVariables>
                            <cucumber.filter.tags>${TEST_SUITE}</cucumber.filter.tags>
                            <cucumber.glue>balsambrands_automation.hooks,balsambrands_automation.step_definitions${PROJECT}</cucumber.glue>
                            <cucumber.features>src/test/java/balsambrands_automation/feature_files</cucumber.features>
                            <cucumber.plugin>json:target/cucumber/test-report.json,junit:target/cucumber/report.xml</cucumber.plugin>
                        </systemPropertyVariables>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
© www.soinside.com 2019 - 2024. All rights reserved.