I want to create a simple unit test of expected logging (level and message) in a try/catch scenario.
One exception should log a info-message with a specified message and other exception should log warning messages.
I am using the following dependency: implementation("io.github.oshai:kotlin-logging-jvm:7.0.0")
My first attempt of this is done by logging with an object which I can mock in a unit test:
private val logger = KotlinLogging.logger {}
object MyLogger {
fun info(exception: Exception, msg: String) {
logger.info(exception) { msg }
}
fun warn(exception: Exception, msg: String) {
logger.warn(exception) { msg }
}
}
I do not like this solution as code is introduced for the purpose of testing only. Is there a way where I can test invocations of the logger directly.
I am using testImplementation("io.mockk:mockk-jvm:1.13.11")
for mocking purposes