Sometimes is shows up as a hard task to debug a simple test case method as there should be some rules to meet, dependencies to inject, or configurations to initialize and that may be out of the current test class scope.

If your are using Maven as your build tool, there is an ultimate method as you can run your tests using the maven surfire plugin attached for remote debug on some port.
Just run the test phase with maven.surefire.debug system property:

mvn test -Dmaven.surefire.debug

This will attach the debugger to listen on port 5005 (used by default), so just configure your favorite IDE to attach to that port and set up a break point.

You can even change the port number using:

mvn clean test -Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -Xnoagent -Djava.compiler=NONE"
This will attach the jvm process to listen on 8000 port.

blog comments powered by Disqus


17 August 2014