testing - Gradle:如何在控制台实时显示测试结果?

标签 testing console gradle

我希望在我运行的同一个控制台中看到测试结果(system.out/err,来自被测试组件的日志消息)运行:

gradle test

并且不要等到测试完成后再查看测试报告(只有在测试完成时才会生成,所以我不能在测试运行时“tail -f”任何东西)

最佳答案

这是我喜欢的版本:

fancy test result

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

tasks.withType(Test) {
    testLogging {
        // set options for log level LIFECYCLE
        events TestLogEvent.FAILED,
               TestLogEvent.PASSED,
               TestLogEvent.SKIPPED,
               TestLogEvent.STANDARD_OUT
        exceptionFormat TestExceptionFormat.FULL
        showExceptions true
        showCauses true
        showStackTraces true

        // set options for log level DEBUG and INFO
        debug {
            events TestLogEvent.STARTED,
                   TestLogEvent.FAILED,
                   TestLogEvent.PASSED,
                   TestLogEvent.SKIPPED,
                   TestLogEvent.STANDARD_ERROR,
                   TestLogEvent.STANDARD_OUT
            exceptionFormat TestExceptionFormat.FULL
        }
        info.events = debug.events
        info.exceptionFormat = debug.exceptionFormat

        afterSuite { desc, result ->
            if (!desc.parent) { // will match the outermost suite
                def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
                def startItem = '|  ', endItem = '  |'
                def repeatLength = startItem.length() + output.length() + endItem.length()
                println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
            }
        }
    }
}

关于testing - Gradle:如何在控制台实时显示测试结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3963708/

相关文章:

ruby-on-rails - Ruby on Rails : RSpec and Acts As Audited (disabling acts_as_audited while testing?)

python - Django 在/src/project 之外提取测试

ios - 用 println() 打印 `po` 对象描述?

c# - 如何在控制台中正确书写英文转录?

android - 如何增加 Gradle 守护程序的最大堆大小?

winforms - 在 Beta 测试期间检测异常

reactjs - Jest 测试组件的内部方法

c# - 控制台图表绘制

android - 在新的 Android Studio 3.1 上构建时出错

android - list 合并失败 - 支持 :appcompat-v7:26. +