Gradle starts tests in a separate process form the main build script process, so if you want to debug them you have to configure the test task with jvm debug args.
For example:
test.doFirst {
jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
}
If you "gradle test" the build process will run and suspend on the test task.
You can then attach a remote debugger to see what is going on