Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: how to list all "given tests"

I try the following code:

roroco@roroco ~/Dropbox/jvs/ro-idea $ gradle test --tests "ro.idea.ToggleTest.testIsAd"
:ro:compileJava UP-TO-DATE
:ro:processResources UP-TO-DATE
:ro:classes UP-TO-DATE
:ro:jar
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources UP-TO-DATE
:testClasses
:test
:ro:compileTestJava UP-TO-DATE
:ro:processTestResources UP-TO-DATE
:ro:testClasses UP-TO-DATE
:ro:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':ro:test'.
> No tests found for given includes: [ro.idea.ToggleTest.testIsAd]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

The output show "No tests found for given includes", my question is: how to list all "given tests" and how to specify "given tests"

this is my old question

like image 451
zizhuo64062kw Avatar asked Nov 10 '14 03:11

zizhuo64062kw


2 Answers

I am unsure about list all the given tests prior to executing since I don't believe this is known until the testing actually executes.

What you could so is add this to your build.gradle file:

test {
  beforeTest { descriptor ->
     logger.lifecycle("Running test: ${descriptor}")
  }
}

Then if you go:

gradle clean test

It will run all tests but will also print out the test descriptor before it executes providing the method(className) which will look like so:

:test
Running test: test testC(org.gradle.MySecondTest)
Running test: test testD(org.gradle.MySecondTest)
Running test: test testA(org.gradle.MyFirstTest)
Running test: test testB(org.gradle.MyFirstTest)

Alternatively you can just run the previous command without the build.gradle file change and look at your build/reports/tests/index.html file which will show all tests run.

So then you could specify a single test with:

gradle clean test --tests "org.gradle.MyFirstTest.testA"

Or all tests in a class:

gradle clean test --tests "org.gradle.MyFirstTest"

Or all tests in a package:

gradle clean test --tests "org.gradle.*"
like image 186
Welsh Avatar answered Oct 08 '22 07:10

Welsh


You can also use:

test {
    testLogging {
        events "passed", "skipped", "failed"
    }
}
like image 21
Igor Avatar answered Oct 08 '22 08:10

Igor