Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to debug maven surefire test more easily (using eclipse as debug server)

I'm using maven / surefire / eclipse to write some code and later test / debug it.

Standard way to do it is by using maven.surefire.debug maven property. By default, when this property is enabled, maven starts listening on port 5005 and I can attach to the debugged process using remote debugger. When the test finishes remote debugger disconnects from the server.

This process involves two steps when done using in eclipse:

  1. Run maven
  2. Connect using remote launch configuration

What I would like to achieve is to reduce this to:

  1. Run maven

I have found, that setting the maven.surefire.debug property to some remote debug options will change the remote debug behaviour. Thus when I specify i.e.

-Dmaven.surefire.debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=5005"

then build will try to connect to my eclipse process listening on port 5005. This way I invert the default client/server roles of maven and eclipse.

However there is one big problem with this approach. It doesn't give me anything, as after maven build finishes, eclipse stops listening on server port. This is the part that I don't understand. When I connect as debug client from eclipse to for example WebLogic server, it allows me to connect / disconnect freely as many times as I want.

Anyone knows if this is normal, or maybe I need to specify some additional options to make debugging maven tests easier?

like image 774
mateusz.fiolka Avatar asked Sep 24 '10 14:09

mateusz.fiolka


People also ask

How do I debug a custom Maven plugin?

If you start your build with mvnDebug clean install instead of mvn clean install Maven will wait for a remote debugger to connect on port 8000 . This should work for all plugin that to not run in their own JVM. This requires Maven greater than 2.0. 8 which I assume you are running.

How do I debug in eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.


1 Answers

Simple way:

1. Open the Debug As > .. dialogue box 2. In the goal text box, give      -DforkMode=never test 3. Run the debug project 
like image 58
Zeba Ahmad Avatar answered Sep 28 '22 12:09

Zeba Ahmad