-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_report.gradle
More file actions
74 lines (58 loc) · 2.58 KB
/
test_report.gradle
File metadata and controls
74 lines (58 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* SPDX-FileCopyrightText: 2006-2026 Peter Jakubčo
SPDX-License-Identifier: GPL-3.0-or-later */
// Credits go to: https://gist.github.com/lwasyl/f5b2b4ebe9e348ebbd8ee4cb995f8362#file-gradle_tests_report-gradle
// https://medium.com/@wasyl/pretty-tests-summary-in-gradle-744804dd676c
import groovy.time.TimeCategory
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
ext.testsResults = [] // Container for tests summaries
allprojects { project ->
tasks.withType(Test).configureEach { 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 = false // true to always 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}"}┘"
}