Logback - ユニットテストでのロギングを無効にする

ログバック-単体テストでのログ記録を無効にする

IDEで単体テストが実行されている間、Logbackは次のような多くの構成またはステータスを表示しています。

21:16:59,569 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
21:16:59,569 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
21:16:59,569 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at ...

//... omitted for readability.

21:17:00,051 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ch.qos.logback]
21:17:00,051 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to OFF
21:17:00,051 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
21:17:00,051 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
21:17:00,053 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@20e2cbe0 - Registering current configuration as safe fallback point

java.lang.AssertionError:
Expected: is (3)
     but: was (2)

    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
    at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)

特に失敗したテストの場合、エラーメッセージを手動で下にスクロールする必要があるため、本当に面倒です。

1. 解決策-空の構成

これを修正するには、空の構成ファイルをlogback-test.xmlとして作成し、$project/src/test/resourcesの下に保存します。

$project/src/test/resources/logback-test.xml

ユニットテストを再度実行します。意味のないsilence is goldenはもうありません。

2. ソリューション-NopStatusListener

または、次のようにNopStatusListenerを追加します。

logback-test.xml



    

    
        
            
                %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n