Created
September 2, 2020 07:52
-
-
Save paliwodar/090a05a0c0e050d9922cadf6ccb7fc05 to your computer and use it in GitHub Desktop.
Gradle test logging
This file contains hidden or 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
test { | |
testLogging { | |
events "skipped", "failed", "standardError" | |
def outputCache = new LinkedList<String>() | |
beforeTest { TestDescriptor td -> outputCache.clear() } // clear everything right before the test starts | |
onOutput { TestDescriptor td, TestOutputEvent toe -> // when output is coming put it in the cache | |
outputCache.add(toe.getMessage()) | |
while (outputCache.size() > 1000) outputCache.remove() // if we have more than 1000 lines -> drop first | |
} | |
/** after test -> decide what to print */ | |
afterTest { TestDescriptor td, TestResult tr -> | |
if (tr.resultType == TestResult.ResultType.FAILURE && outputCache.size() > 0) { | |
println() | |
println(" Output of ${td.className}.${td.name}:") | |
outputCache.each { print(" > $it") } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment