Debug functional tests from IntelliJ

744 views Asked by At

I'm working on a Grails app that has a suite of (Geb) functional tests. I used to be able to debug these tests from inside IntelliJ, but now whenever I try to run the tests in debug mode I get the following error

ERROR: transport error 202: connect failed: Connection refused
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
1

There are 1 answers

0
defectus On

Since the introduction of the fork mode I'd been struggling with debugging until I discovered this simple trick. In your BuildConfig.groovy change the grails.project.fork to something like this:

grails.project.fork = [
   test   : [maxMemory: 1024, minMemory: 128, debug: false, maxPerm: 256, daemon:false, jvmArgs: ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005']],
   run    : [maxMemory: 1280, minMemory: 128, debug: false, maxPerm: 256, forkReserve: true, jvmArgs: ['-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005']],
   war    : false,
   console: [maxMemory: 1024, minMemory: 128, debug: false, maxPerm: 256]
]

Notice the jvmArgs in the run and test configurations. This is simple passed onto Java when the fork mode executes.

Next you have to configure remote debugging hooking onto the port as defined in the previous step.

For your convenience you can configure an external tool to wait for the debug to come alive and then start the debug session. Basically it run an nc in a loop until a specified port is alive. In the simplest form it looks like this:

#!/usr/bin/env bash
while ! nc -z localhost 5005; do sleep 0.1; done;

You can configure this script as an external tool and make it run before the debug starts (add it to the 'before launch' box when configuring a new remote debug session)