Reputation: 19945
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.
Upvotes: 105
Views: 73084
Reputation: 10512
There is at least now documentation by JetBrains at https://www.jetbrains.com/help/idea/work-with-tests-in-maven.html#debug_maven
That is:
socket
, host localhost
and set the port
to something other than 5005 (replace below) and just leave the rest to defaultmvn -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:{port}" -Dtest=YourTestClassName test
suspend=y
, the surefire process will pause when starting the test VM, at this point you start the remote debug "build" in IntelliJ.The JetBrains guide says to run in IDE and that does work, but I found it easier to just run in a separate shell.
You really want to restrict to a single test class, otherwise you'll have to reconnect for every single class.
Disabling forking had no impact at all for me, at least with Quarkus tests.
Upvotes: 1
Reputation: 3495
http://maven.apache.org/plugins/maven-surefire-plugin/examples/debugging.html
-DforkMode=never
-DforkCount=0
In IDEA, open your run/debug configuration, in Runner
tab, add fork options -DforkCount=0
Upvotes: 235
Reputation: 21
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:
I hope thats helps you!
Upvotes: 1
Reputation: 391
-DforkMode=never
doesn't work anymore, it is now deprecated in SureFire.
Use -DforkCount=0
instead when using surefire plugin 2.14+.
Upvotes: 29
Reputation: 824
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.
Upvotes: 10
Reputation: 93197
What about a right click on your goal and "Debug [your goal]" (in your case the test goal)?
Upvotes: 27
Reputation: 9168
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.
Upvotes: 36