A test implementation of SLF4J that stores log messages in memory and provides methods for retrieving them. This implementation supports all versions of SLF4J including 1.8.X which have a new binding mechanism.
The easiest way is to include it in your project(s) by ways of a Maven dependency. Binary, Sources and Javadocs are all available from Maven Central.
<dependency>
<groupId>com.github.valfirst</groupId>
<artifactId>slf4j-test</artifactId>
<version>2.4.0</version>
</dependency>
org.slf4j:slf4j-api |
com.github.valfirst:slf4j-test |
---|---|
1.8.0-beta0 - 2.0.0-alpha2 |
1.3.0 - 2.3.0 |
2.0.0-alpha3 - 2.0.0-alpha5 |
2.4.0 |
SLF4J Test provides JUnit Platform extension which can registered via annotation:
import org.junit.jupiter.api.extension.ExtendWith;
import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension;
@ExtendWith(TestLoggerFactoryExtension.class)
class BasicJUnit5Test {
...
}
SLF4J Test supports automatic extension registration via ServiceLoader mechanism. This feature is considered advanced in JUnit Platform and it requires explicit enabling.
This project is based on the original implementation by Robert Elliot, located at https://github.com/Mahoney/slf4j-test which worked with SLF4J prior to version 1.8.X.
See http://projects.lidalia.org.uk/slf4j-test for details.