Inspect the contents of log output during Java unit test (no mock used)

Overview

Inspect the contents of log output during unit test (no mock used)

environment

Method explanation

See Sample Code for the detailed method.

In theory,

The flow.

Note that if you leave Appender added to the root logger and do not detach it, you will retain logging for all subsequent tests.

Digression

I wrote it on the assumption that it will be added to the root logger, but if you specify the logger in detail (like getLogger ("jp.co.hoge ")) and add ʻAppender` there, only that part will be logged. It is also possible.

Recommended Posts

Inspect the contents of log output during Java unit test (no mock used)
Check the contents of the Java certificate store
Memo: [Java] Check the contents of the directory
Output of the book "Introduction to Java"
[Java] [Spring] Test the behavior of the logger
JAVA: jar, aar, view the contents of the file
Automatic creation of Java unit test result report
Format of the log output by Tomcat itself in Tomcat 8
Test the contents of an Excel file with JUnit
Java: Use Stream to sort the contents of the collection
About Java log output
Java Unit Test Library-Artery-Sample
[Note] Java Output of the sum of odd and even elements
I want to change the log output settings of UtilLoggingJdbcLogger
How to mock some methods of the class under test
Test the behavior of the log output logger when using an external logging API such as SLF4J