How to configure gradle to display the total number of tests performed?

While the tests are running, the number of running tests is shown ephemerally, but how can I print the total number of tests that were run on the console after all the tests?

Setting testLogging does not help. I can make gradle output the result for each test, for example:

 testLogging { events "passed", "skipped", "failed" } 

But I want to get the final “final line”, which displays the total number of running tests, even if all of them passed.

+6
source share
2 answers

You can use the afterSuite closure with the TestResult argument. FE (borrowed from https://gist.github.com/orip/4951642 ):

 test { testLogging { afterSuite { desc, result -> if (!desc.parent) { // will match the outermost suite println "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" } } } } 
+5
source

Using Gradle 2.12 with a simple project (with two test suites), this script:

 apply plugin: 'java' repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.12' } def numTests = 0 test { beforeTest { descriptor -> logger.lifecycle("Running test: " + descriptor) numTests++ } } test << { println "\nnumTests executed: ${numTests}" } 

gives this output (for me):

 bash$ gradle clean test :clean [snip] :test Running test: Test test1(net.codetojoy.ActorTest) Running test: Test test2(net.codetojoy.ActorTest) Running test: Test test3(net.codetojoy.ActorTest) Running test: Test test4(net.codetojoy.ActorTest) Running test: Test test1(net.codetojoy.SniffTest) Running test: Test test2(net.codetojoy.SniffTest) Running test: Test test3(net.codetojoy.SniffTest) Running test: Test test4(net.codetojoy.SniffTest) Running test: Test test5(net.codetojoy.SniffTest) Running test: Test test6(net.codetojoy.SniffTest) numTests executed: 10 
+1
source

All Articles