Created
July 29, 2020 19:10
-
-
Save michellescripts/e36c9f0a25a52363d07c27bde0d5f551 to your computer and use it in GitHub Desktop.
add to your build.gradle.kts to print your test results in a readable way!
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
tasks.withType<Test> { | |
systemProperty("junit.jupiter.execution.parallel.enabled", true) | |
testLogging { | |
// set options for log level LIFECYCLE | |
events( | |
TestLogEvent.FAILED, | |
TestLogEvent.PASSED, | |
TestLogEvent.SKIPPED, | |
TestLogEvent.STANDARD_ERROR | |
) | |
exceptionFormat = TestExceptionFormat.FULL | |
showExceptions = true | |
showCauses = true | |
showStackTraces = true | |
// set options for log level DEBUG and INFO | |
debug { | |
events( | |
TestLogEvent.STARTED, | |
TestLogEvent.FAILED, | |
TestLogEvent.PASSED, | |
TestLogEvent.SKIPPED, | |
TestLogEvent.STANDARD_ERROR, | |
TestLogEvent.STANDARD_OUT | |
) | |
exceptionFormat = TestExceptionFormat.FULL | |
} | |
info.events = debug.events | |
info.exceptionFormat = debug.exceptionFormat | |
} | |
var failures = "" | |
addTestListener(object : TestListener { | |
override fun beforeSuite(suite: TestDescriptor) {} | |
override fun beforeTest(testDescriptor: TestDescriptor) {} | |
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) { | |
if (result.resultType === TestResult.ResultType.FAILURE) { | |
failures += " * ${testDescriptor.className} > \n\t${testDescriptor.name}\n" | |
} | |
} | |
override fun afterSuite(suite: TestDescriptor, result: TestResult) { | |
if (suite.parent === null) { // will match the outermost suite | |
val purple = "\u001B[35m" | |
val red = "\u001B[31m" | |
val reset = "\u001B[0m" | |
val output = | |
"Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" | |
val divider = "\n**********************************************************************************\n" | |
println(divider) | |
if (failures === "") { | |
print(purple) | |
println( | |
""" | |
____ _ _ ____ ____ U _____ u ____ ____ | |
/ __"| u U |"|u| | U /"___| U /"___| \| ___"|/ / __"| u / __"| u | |
<\___ \/ \| |\| | \| | u \| | u | _|" <\___ \/ <\___ \/ | |
u___) | | |_| | | |/__ | |/__ | |___ u___) | u___) | | |
|____/>> <<\___/ \____| \____| |_____| |____/>> |____/>> | |
)( (__) (__) )( _// \\ _// \\ << >> )( (__) )( (__) | |
(__) (__) (__)(__) (__)(__) (__) (__) (__) (__) | |
""".trimIndent() | |
) | |
print(reset) | |
} | |
if (failures !== "") { | |
println(red) | |
println( | |
""" | |
( ( ( ( ( | |
)\ ) ( )\ ) )\ ) )\ ) )\ ) | |
(()/( )\ (()/( (()/( ( (()/( ( (()/( | |
/(_)) ((((_)( /(_)) /(_)) )\ /(_)) )\ /(_)) | |
(_))_| )\ _ )\ (_)) (_)) _ ((_) (_)) ((_) (_)) | |
| |_ (_)_\(_) |_ _| | | | | | | | _ \ | __| / __| | |
| __| / _ \ | | | |__ | |_| | | / | _| \__ \ | |
|_| /_/ \_\ |___| |____| \___/ |_|_\ |___| |___/ | |
""".trimIndent() | |
) | |
println("\n") | |
println(failures + reset) | |
} | |
println( | |
""" | |
┬─┐┌─┐┌─┐┬ ┬┬ ┌┬┐┌─┐ | |
├┬┘├┤ └─┐│ ││ │ └─┐ | |
┴└─└─┘└─┘└─┘┴─┘┴ └─┘ | |
""".trimIndent() | |
) | |
println(output) | |
println(divider) | |
} | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment