does kotlint-logging support mocking the logger?
# kotlin-logging
c
does kotlint-logging support mocking the logger?
o
christophsturm: I think it is more a part of the underlying logging framework, but you can see an example here: https://github.com/MicroUtils/kotlin-logging/blob/master/src/test/kotlin/mu/LoggingTest.kt
Copy code
private lateinit var appenderWithWriter: AppenderWithWriter

    @Before
    fun setupAppender() {
        appenderWithWriter = AppenderWithWriter()
        Logger.getRootLogger().addAppender(appenderWithWriter.appender)
    }

    @After
    fun removeAppender() {
        Logger.getRootLogger().removeAppender(appenderWithWriter.appender)
    }
c
ah interesting so i add an appender and check that.
usually i would just overwrite the java field of the logger with a mocked logger and verify the log method call. that also avoids log output in my tests. but i don’t know how to do that with kotlin-logging or how it should be done in such a context
o
do you want to test the message or just not to see the logging?
c
testing the message is more important, but both would be great.
o
for testing the message the above is what I think of, in case you don't want to have the message in console/log I think using slf4j-nop https://mvnrepository.com/artifact/org.slf4j/slf4j-nop will work
not sure if both will work together though
and in my opinion it is better to have logging to console in tests
in some cases it helps
c
thanks for your help!
793 Views