In the IntelliJ tests menu for the test you want to debug, click on the dropdown and choose "Edit Configurations..."


That should present you with a window that looks like the following; choose the test you want.


In this window, add the following argument to your "VM options" (leave the -ea flag present):

-Ddunit.debug.basePort=29999

This causes a debug port to be opened in each DUnit VM. VM 0 has port 30000, VM 1 has port 30001, and on up. Click the "+" in the "Run/Debug Configurations" menu, and add a new Remote configuration. Call this configuration "DUnit VM 0". Debugger mode should be "attach to remote JVM", localhost port 30000, configuration should have the following arguments for the remote JVM:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=30000


Create more configurations for each additional VM you want to attach to, increasing the port number by 1 for each VM.

If you wish to always enable debugging whenever you run a test, you may also modify the JUnit Template and add the above property. That way IntelliJ will always add it to every JUnit test configuration avoiding the need for repeated setup.

To avoid issues with membership timeouts, make sure to set the breakpoint suspend setting to `Thread` rather than `All` so that the membership health check thread is not paused when the debugger is at a breakpoint.  This will of course only work if the breakpoint is not in the membership health checking thread itself, but that should be rare occurrence.  See the below picture for how to change this setting - it may be useful to set `Thread` as default by pressing the `Make Default` button as well.

If debugging needs to happen very early in the JVM  startup, it may be necessary to suspend the JVM so that you have time to attach the debugger. Setting the following property allows a particular DUnit VM to be suspended - in this example VM 0:

-Ddunit.debug.suspendVM=0


To debug your test normally (I normally put a breakpoint in a @Before method or at the beginning of the test if I want to pause the other VMs), and then select "DUnit VM 0" from the test dropdown (the same one in the first picture, where you chose "Edit Configurations"). Then hit the debug symbol, and as long as the VM has started, you should be connected! Breakpoints will work normally and you can switch between tabs to debug all your VMs!



  • No labels

1 Comment

  1. I believe Jens has made some changes to the dunit launcher that we don't fire up a default locator in the dunit launcher now, so the baseport can be set to 30000, and vm0 is listening on 30000.