problem: hard to find failing tests on CI

This commit is contained in:
Igor Artamonov
2020-05-13 22:55:19 -04:00
parent 042408b4e6
commit 3729aa040e

View File

@@ -125,7 +125,7 @@ compileTestKotlin {
test {
jvmArgs '-ea'
testLogging.showStandardStreams = true
testLogging.showStandardStreams = false
testLogging.exceptionFormat = 'full'
}
@@ -199,4 +199,38 @@ task generateVersion() {
].join("\n")
}
}
// Show the list of failed tests and output only for them, helpful for CI
ext.failedTests = []
tasks.withType(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 descriptor, TestResult result ->
if(result.resultType == org.gradle.api.tasks.testing.TestResult.ResultType.FAILURE){
failedTests << "${descriptor.className} > ${descriptor.name}"
if (!stdout.isEmpty()) {
println("-------- ${descriptor.className} > ${descriptor.name} OUTPUT ".padRight(120, "-"))
stdout.each { print(it) }
println("================".padRight(120, "="))
}
}
}
}
gradle.buildFinished {
if(!failedTests.empty){
println "Failed tests for ${project.name}:"
failedTests.each { failedTest ->
println failedTest
}
println ""
}
}