NaN
NaN

Reputation: 8581

Debug gradle test from within eclipse

Is it possible to debug a gradle test started with

gradle test

on CLI from within eclipse? Can I add the JVM args like

java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 ....

for remote debugging as I would do it for a normal Java program?

Upvotes: 13

Views: 14564

Answers (3)

Markus Weninger
Markus Weninger

Reputation: 12638

Solution:

I prefer gradle test --debug-jvm. This starts the application in remote debug mode, and you can attach with any remote debugger, e.g., Eclipse, on port 5005. This does not only work for JUnit tests, but also for normal program executions, i.e., gradle run --debug-jvm.


Debugger Example - Eclipse:

In Eclipse, go on your Project -> Debug as... -> Debug Configuration -> Remote Java Application. As host set localhost, as port 5005.

Then you should be able to debug your tests.


Additional Info:

For more information see the official Gradle Java plugin doc regarding testing.

[...] can also be enabled at invocation time via the --debug-jvm task option (since Gradle 1.12).

Upvotes: 9

David M. Karr
David M. Karr

Reputation: 15205

Is it just a JUnit class you want to debug? If so, just debug the JUnit class directly in Eclipse, with "Debug As".

Upvotes: 1

NaN
NaN

Reputation: 8581

The gradle option is -Dtest.debug. Then you can connect via eclipse on port 5005.

Upvotes: 10

Related Questions