Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run the IntelliJ debugger on unit tests in a Maven project?

I'm working with a multi-artifact Maven project where artifacts in the project have a few dependencies on each other. I am using IntelliJ 9. I'd like to be able to set breakpoints in my unit tests, but when I right-click on the unit tests folder for my artifact and choose "Debug 'All Tests'", I get a Class not found exception referring to a class in a separate Maven artifact.

I can run the Maven "test" goal on the parent artifact and it works fine.

Any ideas? Thanks.

like image 590
Jon Onstott Avatar asked Jul 01 '11 22:07

Jon Onstott


People also ask

How do I debug Maven tests in IntelliJ?

In the IDE, add debug points where you want the debugger to pause during execution. Then in the terminal, enter your Maven execution command, replacing mvn with mvnDebug . In IntelliJ, make sure your debugging configuration is selected, then press the “Debug” button.

How do I debug a unit test in IntelliJ?

If you don't know why a test fails, you can debug it. In the editor, click the gutter on the line where you want to set a breakpoint. There are different types of breakpoints that you can use depending on where you want to suspend the program. For more information, refer to Breakpoints.

How do I run an IntelliJ test in Maven?

Run testsOpen the Maven tool window. Under the Lifecycle node select test. Note that goals specified in the Maven surefire plugin will be activated at this phase and all tests in a project or in a module will be run.


1 Answers

In you run Maven from command line, you will be able to run it with debugger enabled and just attach Idea as remote debugger. That's how I usually use it.

mvn -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE" test

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

This will allow debugger connection to port 8000 and wait for you to attach before execution.

like image 92
Alex Gitelman Avatar answered Oct 06 '22 00:10

Alex Gitelman