slf4j-junit
slf4j-junit enables verification of logging made with SLF4J.
Getting Started
We create a normal JUnit test, and we add a JUnit TestRule in order to enable the verification of logging within the test.
import org.junit.Rule; import static uk.co.webamoeba.slf4j.junit.LogVerification.enableLogging; public class SomeTest { @Rule public EnableLogging enableLogging = enableLogging(); }
We can now create a test, and verify that some logging has taken place:
import static uk.co.webamoeba.slf4j.junit.LogVerification.verifyLogger; import static uk.co.webamoeba.slf4j.junit.log.Level.INFO; ... public void shouldDoSomething() { // Given String someArgument = "Hello everyone!"; // When something.doSomething(someArgument); // Then verifyLogger(Something.class).logged(INFO, "I saw the 'Hello everyone!'"); }