gpt4 book ai didi

gradle - 无法解析符号testLogging,事件,exceptionFormat- Gradle

转载 作者:行者123 更新时间:2023-12-03 03:18:52 27 4
gpt4 key购买 nike

我正在尝试通过以下信息将更多日志打印到控制台:
https://stackoverflow.com/a/36130467,但我不断收到这些错误:

  • 无法解析符号测试
  • 无法解决符号事件
  • 无法解决符号异常格式
  • 无法解析符号调试等。

  • 这是我的代码

    build.gradle文件:
    import org.gradle.api.tasks.testing.logging.TestExceptionFormat
    import org.gradle.api.tasks.testing.logging.TestLogEvent

    apply plugin: 'groovy'
    apply plugin: 'idea'
    apply plugin: 'java'

    repositories {
    jcenter()
    mavenCentral()
    }


    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} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
    def startItem = '| ', endItem = ' |'
    def repeatLength = startItem.length() + output.length() + endItem.length()
    println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
    }
    }
    }
    }

    dependencies {
    testImplementation group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.4.10'
    testImplementation group: 'org.spockframework', name: 'spock-unitils', version:'1.1-groovy-2.4-rc-4'
    }

    最佳答案

    使用JUnit 5Gradle 6,以下test任务定义将打印测试的名称和结果:

    test {
    useJUnitPlatform()
    testLogging.events.addAll([TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED])
    }

    如果要汇总有关测试结果的信息,则可以使用以下版本的 test任务。所有测试完成后,这将添加以下报告。
    ----------------------------------------------------------------------
    | Results: SUCCESS (95 tests, 95 successes, 0 failures, 0 skipped) |
    ----------------------------------------------------------------------
    test {
    useJUnitPlatform()
    testLogging.events.addAll([TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED])
    testLogging {
    afterSuite { desc, result ->
    if (!desc.parent) { // group the results in one
    def output = "Results: ${result.resultType} (" +
    "${result.testCount} tests, " +
    "${result.successfulTestCount} successes, " +
    "${result.failedTestCount} failures, " +
    "${result.skippedTestCount} skipped)"
    def startItem = '| ', endItem = ' |'
    def repeatLength = startItem.length() + output.length() + endItem.length()
    println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
    }
    }
    }
    }

    我建议看一下这些文档:
  • https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html
  • https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.logging.TestLogging.html#org.gradle.api.tasks.testing.logging.TestLogging
  • 关于gradle - 无法解析符号testLogging,事件,exceptionFormat- Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49334677/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com