Forked from lwasyl/gradle_tests_report.gradle
Created
September 24, 2021 07:12
Star
You must be signed in to star a gist
Gradle tests logging #loggingpost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.time.TimeCategory | |
import org.gradle.api.tasks.testing.logging.TestExceptionFormat | |
import org.gradle.api.tasks.testing.logging.TestLogEvent | |
rootProject { | |
ext.testsResults = [] // Container for tests summaries | |
allprojects { project -> | |
tasks.withType(Test) { testTask -> | |
testTask.testLogging { logging -> | |
events TestLogEvent.FAILED, | |
TestLogEvent.SKIPPED, | |
TestLogEvent.STANDARD_OUT, | |
TestLogEvent.STANDARD_ERROR | |
exceptionFormat TestExceptionFormat.FULL | |
showExceptions true | |
showCauses true | |
showStackTraces true | |
} | |
ignoreFailures = true // Always try to run all tests for all modules | |
afterSuite { desc, result -> | |
if (desc.parent) return // Only summarize results for whole modules | |
String summary = "${testTask.project.name}:${testTask.name} results: ${result.resultType} " + | |
"(" + | |
"${result.testCount} tests, " + | |
"${result.successfulTestCount} successes, " + | |
"${result.failedTestCount} failures, " + | |
"${result.skippedTestCount} skipped" + | |
") " + | |
"in ${TimeCategory.minus(new Date(result.endTime), new Date(result.startTime))}" + | |
"\n" + | |
"Report file: ${testTask.reports.html.entryPoint}" | |
// Add reports in `testsResults`, keep failed suites at the end | |
if (result.resultType == TestResult.ResultType.SUCCESS) { | |
rootProject.testsResults.add(0, summary) | |
} else { | |
rootProject.testsResults += summary | |
} | |
} | |
} | |
} | |
} | |
gradle.buildFinished { | |
def allResults = rootProject.ext.testsResults | |
if (!allResults.isEmpty()) { | |
printResults allResults | |
} | |
} | |
private static void printResults(allResults) { | |
def maxLength = allResults*.readLines().flatten().collect { it.length() }.max() | |
println "┌${"${"─" * maxLength}"}┐" | |
println allResults.collect { | |
it.readLines().collect { | |
"│" + it + " " * (maxLength - it.length()) + "│" | |
}.join("\n") | |
}.join("\n├${"${"─" * maxLength}"}┤\n") | |
println "└${"${"─" * maxLength}"}┘" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment