When using maven surefire in conjunction with remote debugging (mvnDebug, for instance)
it seems necessary to disable forking of the test executions into separate processes, as the remote debugging works process wise. This is usually done by setting the the fork mode to never, e.g. by specifying -DforkMode=never on the command line.

This is, however, a misunderstanding. mvnDebug is there to enable debugging of the maven process and not of the surefire execution – and disabling forking may have various side effects. One of those is the use of Java agents. When using agents, e.g. for loadtime-weaving in the Spring Framework, one often specifies a -javaagent: as a JVM argument for surefire:


	
	org.apache.maven.plugins
	maven-surefire-plugin
	
		
		-javaagent:/path/to/myagent.jar
	

Java agents however must be provided as an argument to the JVM when it starts – which is exactly what happens when surefire “forks”.
Thus: No forking, no agents, since the tests will be executed in the current jvm used to execute maven itself – and that one was not started with a -javaagent argument. In order to execute surefire tests and use agents, the forkMode must at least be “once” (-DforkMode=once).

Thus, leave the forking as it is, and enable remote debugging as described in the surefire plug-in documentation, i.e. without using mvnDebug:


mvn test -Dmaven.surefire.debug

Which will open a remote debugging port at localhost:5005 for the test execution – and use the agents.

Share →

One Response to Maven, Surefire, remote debugging and the -javaagent switch

  1. lisak says:

    Hey, no problem with debugging tests. The real problem with surefire plugin is debugging the plugin itself… Try to put a breakpoint somewhere in the Mojo and it won’t be triggered.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>