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

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)"
      }
    }
  }
}

Using Gradle 2.12 with a simple project (with 2 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