-
Notifications
You must be signed in to change notification settings - Fork 2
/
setupTestsReports.gradle
executable file
·71 lines (56 loc) · 2.43 KB
/
setupTestsReports.gradle
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
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}"}┘"
}