Mark Malik
05/26/2022, 7:35 AMKoinAppAlreadyStartedException: A Koin Application has already been started
error.
I’m writing a plugin that would connect to the database and check for project specific properties.
The db layer is not part of this project, so for that case the facade should be accessible using Koin.
So in the tests I want to mock the class that is used for db access (I’m using JDBI framework for db) .
This is the test:
internal class HealthPluginTest : WordSpec(), KoinTest {
override fun extensions(): List<Extension> = listOf(KoinExtension(listOf()) { clazz -> mock(clazz.java) })
init {
"HealthCheck Endpoint" should {
"respond from a health running application" {
testApplication {
application { testApplicationModules() }
declareMock<Jdbi> {
given(inTransaction<Boolean, Exception>(any())).willReturn(true)
}
client.get("/monitoring/health-check").apply {
this shouldHaveStatus 200
bodyAsText().shouldContainJsonKeyValue("database", "true")
}
}
}
}
}
private fun Application.testApplicationModules() {
install(Koin)
install(HealthChecks) {
withDbCheck()
}
}
}
Can someone explain what should be the correct setup ?