project.test {
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") }
}
}
}
2条答案
按热度按时间8cdiaqws1#
这可以使用以下Gradle配置进行归档
Git存储库:https://github.com/calliduslynx/gradle-log-on-failure
原始版本可在此处找到:https://discuss.gradle.org/t/show-stderr-for-failed-tests/8463/7
ldxq2e6h2#
将以下配置块添加到您的 build.gradle 文件:
文档可参见here。