26
votes

I am trying to debug Maven tests in IntelliJ IDEA. When I open IDEA's Maven Projects view and right-click on test goal, I get an option to debug it. Clicking it executes this goal but the execution never stops at any breakpoints. What am I missing?

Thanks.

4
Running the app externally to IntelliJ (or Eclipse) using: mvn -Dmaven.surefire.debug test then connecting to the running (but waiting) instance, as @milan has suggested (+1) works for me. - user206428
It seems that the Idea debugger has good support over junit project. I created a debug configuration with junit enabled, and everything worked just fine. - wptoux

4 Answers

22
votes

One solution would be to use remote debugging:

  1. configure the surefire plugin: <debugForkedProcess>true</debugForkedProcess>;

  2. run the test (will wait for a remote debugger to connect)

  3. create and run a remote debug configuration in IntelliJ (will hit your breakpoint); the port to connect to is 5005.
31
votes

Just disable the forked mode - something like this in your pom file (under project/build/plugins section):

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
    <forkMode>never</forkMode>
</configuration>
</plugin>
1
votes

If you're running unit tests with maven failsafe rather than surefire, then debugger will not stop and you have to manually run a failsafe debugger command line and then intellij will be able to stop on the breakpoints. I am unsure if using <forkMode>never</forkMode> option on failsafe solves this issue.

As I describe here: https://github.com/djangofan/maven-failsafe-debug-example

0
votes

Your sources for the dependencies do not match the binary code. Make sure you're using the same sources.