Unit-tests for your logging
AssertLog is a library for unit-testing logging in your application.
Sometimes logging is very important, especially if it contains sensitive information, security incidents, money transfers etc.
Here is how you can use AssertLog:
importorg.assertlog.junit4.log4j.MockLogging;
importorg.junit.Rule;
importorg.junit.Test;
publicclassPetClinicTest {
@RulepublicMockLoggingmockLogging = newMockLogging();
@Testpublicvoidpayment() {
// make a paymentmockLogging.assertLogged("INFO", "Buying 2 Cows for 99.66 eur");
}
@AfterpublicvoidtearDown() {
mockLogging.assertNoMoreLogs();
}
}We plan to support all major Java logging frameworks. Currently only Log4j 1 and JUnit 4 are supported.
You need to add this dependency to you pom.xml:
<dependency>
<groupId>com.codeborne.assertlog</groupId>
<artifactId>assertlog-log4j-junit4</artifactId>
<version>0.1</version>
<scope>test</scope>
</dependency>or build.gradle:
testImplementation('com.codeborne.assertlog:assertlog-log4j-junit4:0.1')AssertLog is open-source project, and distributed under the MIT license.