In IntelliJ, how do i debug a maven test goal?

2019-01-29 19:58发布

Using intellij and maven pom files, how do i debug tests run inside the maven test goal?

When i run them directly in the code, it complains something about profiles missing, which i've ticked inside intellij's Maven Projects.

6条回答
爷、活的狠高调
2楼-- · 2019-01-29 20:16

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

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

查看更多
姐就是有狂的资本
3楼-- · 2019-01-29 20:18

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

debug goal

查看更多
成全新的幸福
4楼-- · 2019-01-29 20:22

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!

查看更多
SAY GOODBYE
5楼-- · 2019-01-29 20:22

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

In IDEA, run your test in debug mode "mvn -DforkMode=never test"

Updated: Open your run/debug configuration, in "Runner" tab, add -DforkMode=never

enter image description here

(Noted by @mikeapr4: newer versions of the surefire plugin (2.14+) use mvn -DforkCount=0 test)

查看更多
成全新的幸福
6楼-- · 2019-01-29 20:27

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.

查看更多
Melony?
7楼-- · 2019-01-29 20:30

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.

查看更多
登录 后发表回答