Jon Onstott
Jon Onstott

Reputation: 13727

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.

Upvotes: 10

Views: 23044

Answers (3)

Suraj
Suraj

Reputation: 327

Try adding this to the maven command: -DforkCount=0 i.e clean verify -DforkCount=0

Upvotes: 0

Jon Onstott
Jon Onstott

Reputation: 13727

I wanted to run the unit tests for a specific package.

I was able to get this to work by making a new JUnit run/debug configuration in IntelliJ. I told it to run the tests in the specific package and for "Use classpath and JDK of module", I picked the root Maven artifact.

Upvotes: 3

Alex Gitelman
Alex Gitelman

Reputation: 24722

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.

Upvotes: 16

Related Questions