I wrote this, and it’s working for me. It only saves the last 100 lines of output. I’d love to see something like this get added to Gradle:
// If a test fails, print its stdout/stderr to the console.
project.test {
def stdout = new LinkedList<String>()
beforeTest { TestDescriptor td ->
stdout.clear()
}
onOutput { TestDescriptor td, TestOutputEvent toe ->
stdout.addAll(toe.getMessage().split('(?m)$'))
while (stdout.size() > 100) {
stdout.remove()
}
}
afterTest { TestDescriptor td, TestResult tr ->
if (tr.resultType == TestResult.ResultType.FAILURE && stdout.size() > 0) {
println()
println("${td.className}.${td.name} failed, output:")
stdout.each { print(it) }
}
}
}