使用 intellij 和 maven pom 文件,我如何调试在 maven 测试目标内运行的测试?
当我直接在代码中运行它们时,它会抱怨缺少配置文件,我已经在 intellij 的 Maven 项目中勾选了它。
http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html
-DforkMode=never
-DforkCount=0
在 IDEA 中,打开您的运行/调试配置,在
Runner
选项卡中,添加 fork 选项-DforkCount=0
我使用以下选项执行测试:
mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=6666 -Xnoagent -Djava.compiler=NONE" test
...然后使用远程调试器连接到 Maven。
-DforkMode=never
不再起作用,它现在已在 SureFire 中弃用。
使用 surefire 插件 2.14+ 时使用
-DforkCount=0
代替。
右键单击您的目标并“调试[您的目标]”(在您的情况下是测试目标)怎么样?
问题已回答。但只是分享我自己的经验。 选择的答案没有解决我的问题。 我的代码有多个模块。
foolshat 的回复确实为我的问题带来了宝贵的见解。
我有两个解决方案, 1. 使用您的 IDEA,通过添加 VM 选项
-DforkMode=never
;必须以调试模式运行它。
2.设置远程调试,指定套接字,在这种情况下不需要forkMode。
这只是我所经历的总结。
mvn 干净验证-DforkCount=0 使用 surefire 插件时
我已经尝试了所有 -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>