In many cases we want to test if our application logging is implemented in proper way.
This is another easy way to testing what our application logs when we use slf4j framework.
Using slf4j-mock we can mock all logger and assert it as we do with other mocked method.
Feature of library:
this binding support for easy create Mockito mock for Logger
call to Logger can be delegated to instance of SimpleLogger,
so we can create standard simplelogger.properties
support for testing and mocking MDC
light transitive dependencies - only slf4j-api and mockito-core
support testing in parallel in multi thread
all the Magic are done by Mockito plugins, so you don’t need to directly use class from this library
ease use
First we should add slf4j-mock binding as dependency to our project,
we must remember that we can have only one slf4j binding on classpath.
Now we have class which does some logging action
And finally we write test for it
As we see thanks mocking slf4j logger we can prepare test for many scenario which we want.