Debugging Maven tests

Goal

We want to execute Maven lifecycle with the ability to connect our IDE to the tests so that we may debug them

Description

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

How to

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"

Explanations

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s