I'm trying to debug my unit tests using IntelliJ remote debugging feature.
The project I'm maintaining is based on an old version of play framework (2.4), and I'm currently trying to configure IntelliJ to launch the unit tests in debug mode. Here's what I managed to do so far:
- I configure my build.sbt to launch the tests jvm in debug mode by adding the following:
javaOptions in Test += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9990"
- I run the tests using "activator test"
- as soon I see "Listening for transport dt_socket at address: 9990" I run my IntelliJ debug configuration configured to hook up to localhost:9990
This works perfectly and allows me to debug my code as expected, but the workflow isn't the best, so I've been trying to tweak my remote debug configuration to achieve the above on a single click. I basically add a "Run External Tool" to my debug configuration under "Before Launch: activate tool window" and make it run "activator test" under the proper working directory which launches the tests properly when I run the configuration but doesn't hook up the debugger.
The problem is I can't think of a way to instruct my IntelliJ debug configuration to hook up with the tests jvm when it gets launched by activator.
Note that activator doesn't launch the jvm on which the tests run immediately, it takes it a few seconds to load other stuff before doing so.
Why not use the debug test menu item to launch tests? because for some reason in debug mode the vm loads the original app config file instead of a test config I specify in my build.sbt as follows
javaOptions in Test += "-Dconfig.file=conf/test-application.conf"
This behavior causes my tests to fail due to configuration conflicts. Note that this happens only in debug mode, as opposed to "run" mode where my test config file is loaded properly allowing my tests to run as expected.
Any hints are appreciated.