Logback and SLF4j unit testing.
Original idea from thekua's blog, forked from his repo in order to provide it conveniently with good reuse as maven dependency.
Get it via JitPack, for example using maven.
Add the following maven repository to your POM.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add the actual dependency
<dependency>
<groupId>com.github.schnatterer</groupId>
<artifactId>logback-spike</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
From here it's really simple to use:
// Given
LogbackCapturingAppender capturing = LogbackCapturingAppender.weaveInto(OurDomainWithLogger.LOG);
// when
new OurDomainWithLogger().logInfo("This should be logged{}", "!");
// then
assertThat(capturing.getCapturedLogMessages().get(0), is("This should be logged!"));
See LogbackCapturingAppender's javadoc and its unit test for more insights.