From 3729aa040e23a5403871fee3ac065a0c7bfac299 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Wed, 13 May 2020 22:55:19 -0400 Subject: [PATCH] problem: hard to find failing tests on CI --- build.gradle | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 239c1df2..37f46840 100644 --- a/build.gradle +++ b/build.gradle @@ -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() + 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 "" + } } \ No newline at end of file