Last active
November 5, 2021 21:14
-
-
Save mertceyhan/d9fe1d7779f49ec700f98721b098d5ec to your computer and use it in GitHub Desktop.
A logger for Gradle local unit test runner command
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
// Project level build.gradle file | |
subprojects { | |
tasks.withType(Test::class.java) { | |
testLogging { | |
showCauses = false | |
showExceptions = false | |
showStackTraces = false | |
showStandardStreams = false | |
val ansiReset = "\u001B[0m" | |
val ansiGreen = "\u001B[32m" | |
val ansiRed = "\u001B[31m" | |
val ansiYellow = "\u001B[33m" | |
fun getColoredResultType(resultType: ResultType): String { | |
return when (resultType) { | |
ResultType.SUCCESS -> "$ansiGreen $resultType $ansiReset" | |
ResultType.FAILURE -> "$ansiRed $resultType $ansiReset" | |
ResultType.SKIPPED -> "$ansiYellow $resultType $ansiReset" | |
} | |
} | |
beforeSuite( | |
KotlinClosure1<TestDescriptor, Unit>({ | |
if (this.className != null) { | |
println() | |
println(this.className?.substringAfterLast(".").orEmpty()) | |
} | |
}) | |
) | |
afterTest( | |
KotlinClosure2({ desc: TestDescriptor, result: TestResult -> | |
println("${desc.displayName} = ${getColoredResultType(result.resultType)}") | |
}) | |
) | |
afterSuite( | |
KotlinClosure2({ desc: TestDescriptor, result: TestResult -> | |
if (desc.parent == null) { | |
println("Result: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)") | |
} | |
}) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment