-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-utils.gradle.kts
36 lines (31 loc) · 1.02 KB
/
test-utils.gradle.kts
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
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.TestDescriptor
import org.gradle.api.tasks.testing.TestResult
// Define a reusable extension function
fun Test.addColoredSummary() {
addTestListener(object : org.gradle.api.tasks.testing.TestListener {
override fun beforeSuite(suite: TestDescriptor) {
// No-op
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {
if (suite.parent == null) { // Only log for the root suite
val green = "\u001B[32m"
val red = "\u001B[31m"
val yellow = "\u001B[33m"
val reset = "\u001B[0m"
println(
"Total: ${result.testCount} tests executed, " +
"${green}${result.successfulTestCount} passed${reset}, " +
"${red}${result.failedTestCount} failed${reset}, " +
"${yellow}${result.skippedTestCount} skipped${reset}."
)
}
}
override fun beforeTest(testDescriptor: TestDescriptor) {
// No-op
}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
// No-op
}
})
}