Skip to content

Instantly share code, notes, and snippets.

@paliwodar
Created September 2, 2020 07:52
Show Gist options
  • Save paliwodar/090a05a0c0e050d9922cadf6ccb7fc05 to your computer and use it in GitHub Desktop.
Save paliwodar/090a05a0c0e050d9922cadf6ccb7fc05 to your computer and use it in GitHub Desktop.
Gradle test logging
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