Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the test in eclipse directly with Run As -> JUnit test, everything is ok, the test succeeds. But through test task, test always fails. Probably some trouble with the encoding of my resource txt file. So I would like to enable debug while I am launching the 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 to enable debug? I run Gradle tasks from Gradle panel in Eclipse, not from the console. Thanks!

like image 586
mefi Avatar asked Mar 31 '14 11:03

mefi


People also ask

How do I run JUnit in debug mode?

In the case of a test failure you can follow these steps to debug it: Double click the failure entry from the Failures tab in the JUnit view to open the corresponding file in the editor. Set a breakpoint at the beginning of the test method. Select the test case and execute Debug As>JUnit Test from the Debug drop down.

How do I run JUnit in Gradle?

In your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.


1 Answers

To debug tests the following argument should be used: --debug-jvm

For example: gradle test --debug-jvm
Gradle will suspend execution right before running tests and wait for debugger connection on port 5005.

For executing only specific tests see https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern

like image 82
Sergey Avatar answered Sep 21 '22 23:09

Sergey