Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michellescripts/e36c9f0a25a52363d07c27bde0d5f551 to your computer and use it in GitHub Desktop.
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!
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