How to debug test cases with JDB and gradle?

I’m trying to learn how to use more command-line tools, mostly for my own edification, but I can’t for the life of me figure out how to debug test classes when they’ve been built with gradle. Plus, if I just use jdb with some -sourcepath and -classpath flags, I get an issue of the test class not having a main method. I assume I have to run gradle test somehow, but how can I plug jdb in and start adding breakpoints and the like? Thank you in advance for any responses.

If you do ./gradlew test --debug-jvm, then when the tests are started it waits for a debugger to attach to the process. (the details like port and so on can be configure, but by default it waits on port 5005 for the debugger to attach).

Then, while it waits, you can start jdb and tell it to attach to that remote process to debug the test execution.