When you’re writing tests in a Java project, sometimes a simple System.out.println() just isn’t enough. You want to step through the code, inspect variables, and understand exactly what’s going on.
If you’ve ever tried to debug your Maven tests using IntelliJ and found that your breakpoints don’t hit, this post is for you.
Let’s walk through how to properly attach a debugger to a Maven test process.
To debug your application or unit tests, you need to attach the debugger to the JVM running your tests, not the Maven build process.
Run this command instead:
mvn clean test -Dmaven.surefire.debug
⚙️ Step 1: Set Up Remote Debug in IntelliJ
-
Go to Run → Edit Configurations.
-
Click + → Remote JVM Debug.
-
Set:
-
Host:
localhost -
Port:
5005 -
Debugger mode: Attach to remote JVM
-
-
Click OK to save.
🧠 Step 2: Attach and Run
Now go back to your terminal where you ran Maven. It’s currently waiting for a debugger.
In IntelliJ, click Debug ▶️ on the remote configuration you just created.
Once connected, IntelliJ will display:
Now run your tests again if needed — and your breakpoints should hit right away 🎯
🚀 Conclusion
If your IntelliJ breakpoints weren’t working before — now you know why.
The magic lies in attaching to the Surefire (test) JVM, not the main Maven process.