Search code examples
testinglogginggradleconfigurationconsole

How to configure gradle to output total number of tests executed?


While tests are running, the number of tests run so far is ephemerally displayed, but how can I print the total number of tests that were run to the console after all tests have run?

Configuring testLogging doesn't help. I can make gradle output a result for every test, like this:

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

But I want a summary "bottom line", that outputs the total number of tests that were run, even if they all passed.


Solution

  • You may use afterSuite closure with TestResult argument. F.e. (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)"
          }
        }
      }
    }