mefi mefi - 1 year ago 180
Java Question

How to enable debug on my JUnit through Gradle test task

I get into trouble while I try to run my JUnit test through gradle test task. While I run test in eclipse directly with Run As -> JUnit test, everything is ok, test succeeds. But through test task, test always fails. Probably some trouble with encoding of my resource txt file. So I would like to enable debug while I am launching test with gradle

in build.gradle, my test task now looks like:

test {
tasks.withType(Compile) {
options.encoding = 'UTF-8'

So what should I do for enable debug? I run gradle tasks from Gradle panel in Eclipse, not from console. Thanks!

Answer Source

As explained under 23.12. Test in the Gradle User Guide, executing gradle test -Dtest.single=MyTestClass -Dtest.debug will suspend the test JVM upon start, and allows to connect an external debugger (such as the Eclipse debugger) on port 5005.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download