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

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

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

61767 次浏览

I execute tests with the following options:

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

... and then connect to Maven with remote debugger.

What about a right click on your goal and "Debug [your goal]" (in your case the test goal)?

debug goal

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

  • When surefire plugin version < 2.14: use -DforkMode=never
  • When surefire plugin version >= 2.14: use -DforkCount=0

In IDEA, open your run/debug configuration, in Runner tab, add fork options -DforkCount=0

enter image description here

The question has been answered. But just to share my own experience. The selected answer did not solve my problem. My code has multiple modules.

foolshat's reply did bring valuable insight to my problem.

I have two solutions, 1. Using your IDEA, by adding a VM option -DforkMode=never; Must run it with debug mode. 2. Set up a remote debugging, specifying the socket and in this case forkMode is not necessary.

It is just a summary for what I have been through.

-DforkMode=never doesn't work anymore, it is now deprecated in SureFire.

Use -DforkCount=0 instead when using surefire plugin 2.14+.

The solution from Colin Hebert is not working to me neither. But fortunelly I found an easy way to debug the test by doing right click on the green triangle appears next to the test method:

Java test class example

I hope thats helps you!

mvn clean verify -DforkCount=0 when using surefire plugin