我有一个在 travis-ci 上运行的大型测试套件,它有文本输出。我想以仅针对失败的测试、显示标准输出和标准错误流的方式配置 gradle。对于已正确执行的所有其他测试,这种情况不应该发生,以便控制台不会被该噪音污染。
我知道如何启用或禁用标准输出/错误日志记录,但我不确定如何使其依赖于测试结果。
这可以使用以下 gradle 配置进行存档
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") }
}
}
}
Git 仓库:https://github.com/calliduslynx/gradle-log-on-failure https://github.com/calliduslynx/gradle-log-on-failure
原文在这里找到:https://discuss.gradle.org/t/show-stderr-for-failed-tests/8463/7 https://discuss.gradle.org/t/show-stderr-for-failed-tests/8463/7
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)