【问题标题】:gradle: disable output explicitly leads to verbose outputgradle:显式禁用输出会导致详细输出
【发布时间】:2014-12-04 12:39:44
【问题描述】:

我使用 gradle 作为 Spring Boot 应用程序的构建工具,但我遇到了一些奇怪的行为。 Gradle 在显式关闭测试输出时显示更多日志记录信息,就好像我根本没有指定任何内容一样。

这很奇怪,因为显式禁用语句应该至少与没有配置一样具有表达性,或者不应该吗?

示例: 如果我将以下几行添加到我的 build.gradle 中,我会在运行 gradle test 时获得更详细的日志输出:

test{
    testLogging {
        showStackTraces = false
        showStandardStreams = false
        showExceptions = false
        showCauses = false
        events "failed"
        exceptionFormat "short"
    }
}

编辑:

我按照@Peter_Niederwieser 的建议将其更改为events = []。现在几乎所有消息都消失了,除了以下一条。有人或其他人知道我如何压制他们吗?我只想显示结果 34 tests completed 可能还有报告链接。

:backend:test
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.pom
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.build/0.6.2.201302030002/org.jacoco.build-0.6.2.201302030002.pom
Download http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.6.2.201302030002/org.jacoco.agent-0.6.2.201302030002.jar
objc[1360]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
08:50:37.135 [Thread-7] INFO  o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@228186d4: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-6] INFO  o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@4d18a206: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-5] INFO  o.s.c.s.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext@5221dfe5: startup date [Sat Dec 06 08:50:35 CET 2014]; root of context hierarchy
08:50:37.135 [Thread-8] INFO  o.s.w.c.s.GenericWebApplicationContext - Closing org.springframework.web.context.support.GenericWebApplicationContext@5a5fbef7: startup date [Sat Dec 06 08:50:36 CET 2014]; root of context hierarchy
08:50:37.166 [Thread-7] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.166 [Thread-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-5] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:50:37.167 [Thread-7] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@65bad9fe: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-6] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c355f75: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-5] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6dd79791: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.168 [Thread-8] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@75a5ec9: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.co                                                                                                                                                                             ntext.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,testConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor]; root of factory hierarchy
08:50:37.175 [Thread-7] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.175 [Thread-6] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.176 [Thread-5] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'
08:50:37.176 [Thread-8] DEBUG o.s.b.f.s.DisposableBeanAdapter - Invoking destroy() on bean with name 'testConfig'

34 tests completed, 9 failed
:backend:test FAILED

【问题讨论】:

    标签: java testing junit gradle


    【解决方案1】:

    默认为events = []。上面的代码设置了events "failed",这将导致更详细的日志记录(每个失败的测试都将单独记录)。

    【讨论】:

    • 您好,谢谢!这确实有很大帮助,但仍然有一些日志输出。我更新了我的问题,你有什么建议吗?
    • 不知道为什么您仍然会看到这个,但尝试将日志配置文件(为您的应用程序选择的日志框架)放入 src/test/resources 以关闭所有日志记录。如果升级到最新的 Gradle 版本有影响,您也可以尝试。
    • Application Logging 设置为 DEBUG,我想保留它。我只想禁用测试任务的输出。
    • 也许应用程序日志被配置为输出到标准输出?
    • 我在哪里可以检查这个?我使用标准的 Spring Boot 配置,而我的 application.properties 根本不包含任何日志记录特定设置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2022-08-24
    • 2011-08-22
    • 2014-11-21
    • 2020-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多