Here is a modified version of the configuration that Youans shared:
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
// ...
tasks.withType(Test) {
testLogging {
// set options for log level LIFECYCLE
events TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces false
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
beforeSuite { desc ->
if (!desc.name.startsWith("Gradle Test")) {
println "\nRunning ${desc.name}"
}
}
afterSuite { desc, result ->
def duration = String.format("%.3f sec", (result.endTime - result.startTime) / 1000)
if (desc.name.startsWith("Gradle Test Executor")) {
def output = "Result: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped) ${duration}"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
return
}
if (!desc.name.startsWith("Gradle Test")) {
println "Tests run: ${result.testCount}, Failures: ${result.failedTestCount}, Errors: 0, Skipped: ${result.skippedTestCount} Time elapsed: ${duration}"
}
}
}
}
Modifications:
- Changed the suite detection to account for
name
patterns
- Removed
TestLogEvent.STARTED
and TestLogEvent.PASSED
from events
- Changed
showStackTraces
to false
It prints the following minimal output:
Running gradle.example.FooTest
FooTest > someLibraryMethod() FAILED
org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0 Time elapsed: 0.045 sec
Running gradle.example.LibraryTest
LibraryTest > someLibraryMethodReturnsTrue() FAILED
org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0 Time elapsed: 0.006 sec
------------------------------------------------------------------------
| Result: FAILURE (3 tests, 1 passed, 2 failed, 0 skipped) 0.331 sec |
------------------------------------------------------------------------
3 tests completed, 2 failed
Of course the stack trace should probably be kept, but this will at least show the expected/actual values at a minimum.