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

TestingMaven 2Intellij Idea

Testing Problem Overview


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.

Testing Solutions


Solution 1 - Testing

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

Solution 2 - Testing

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.

Solution 3 - Testing

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

debug goal

Solution 4 - Testing

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

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

Solution 5 - Testing

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.

Solution 6 - Testing

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!

Solution 7 - Testing

mvn clean verify -DforkCount=0 when using surefire plugin

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJavaRockyView Question on Stackoverflow
Solution 1 - TestingHover RuanView Answer on Stackoverflow
Solution 2 - TestingHenryk KonsekView Answer on Stackoverflow
Solution 3 - TestingColin HebertView Answer on Stackoverflow
Solution 4 - TestingDesertBladeView Answer on Stackoverflow
Solution 5 - TestingRobin LoxleyView Answer on Stackoverflow
Solution 6 - TestingDavid DRMView Answer on Stackoverflow
Solution 7 - TestingAlik TitelmanView Answer on Stackoverflow