Congratulations on this week’s 2.9 release! I am the author of the plugin for the [Gosu language][2].
I was excited to see the new TestKit features, specifically the ability to introduce debugging into GradleRunner.
Unfortunately setting withDebug(true) is not working as I expected. When executing tests, I expected the daemon to pause while waiting for a remote debugger to connect so that I may debug the executing build. However, the build continues unabated.
I’m attaching a small sample project to confirm my understanding; simply unzip it and run $ ./gradlew test.
To be clear, there is nowhere on the sample project which could actually be debugged. For starters, I consider it sufficient if the GradleRunner pauses while waiting for an external debugger - but is this not the intended behavior?
If you configure TestKit to run it debug mode, it does not connect to a different JVM. That means remote debugging is not involved at all.
To make it work open your project in the IDE of your choice, create a debug run configuration for your test class and add the system property org.gradle.testkit.debug=true as JVM parameter. Before you execute the debug run configuration, you’ll need to set a breakpoint in the code under test. As you mentioned in your post, you’ll need to change your sample code to make something debuggable e.g. by extracting a class. Executing the debug run configuration should hit the breakpoint if you exercise the class under test.
I am using IntelliJ and was executing the test(s) with the IJ Gradle test runner**, not the JUnit runner.
Once I used the JUnit runner in conjunction with the JVM arg, I’m back in business. The GradleRunner#withDebug(boolean) method also works as expected.
Thanks Benjamin!
PS I wouldn’t be where I am today without “Gradle In Action”. Thanks again.
**The Jetbrains Gradle test runner calls $ ./gradlew cleanTest test --tests NameOfTestClass and visualizes the results nicely. But as I mentioned above, this method of executing tests is unable to debug a GradleRunner-invoked build. Hopefully future IJ users can learn from my mistake