We want to execute Maven lifecycle with the ability to connect our IDE to the tests so that we may debug them
When we execute a maven lifecycle such as ‘mvn package’, if we have not configured the tests to be skipped, the implemented tests will execute. However, if we wish to debug those tests in our favourite IDE, we need to take some steps. In this recipe, we explain the easiest way to connect to those tests at maven build time
We simply execute the maven statement, such as ‘mvn package’ with the following maven.surefire.debug Java options:
mvn package -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE"
The previous maven argument options will cause the Java process that executes the tests to suspend its execution until a client (the IDE) connects to it. Therefore, all one has to do now, is configure a new remote debug configuration that connects to the listening socket, in this case, in the port 8000.