How to run IntelliJ debugger on unit tests in a Maven project?

I am working on a project with several Maven artifacts, where the artifacts in the project have several dependencies on each other. I use IntelliJ 9. I would like to be able to set breakpoints in my unit tests, but when I right-click on the test modules folder for my artifact and select "Debug" All Tests ", I get a class not found exception belongs to class in a separate Maven artifact.

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

Any ideas? Thanks.

+6
source share
2 answers

I wanted to run unit tests for a specific package.

I managed to get this to work by creating a new JUnit launch / debug configuration in IntelliJ. I said that to run the tests in a specific package and for β€œUsing the classpath and JDK module” I chose the root of the Maven artifact.

+2
source

In launching Maven from the command line, you can start it with the debugger turned on and simply attach Idea as a remote debugger. As usual, I use this.

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 the debugger to connect to port 8000 and wait for you to attach it before execution.

+9
source

Source: https://habr.com/ru/post/891852/


All Articles