Hello all, I’m having problems getting to work KoT...
# kotest
m
Hello all, I’m having problems getting to work KoTest extension for Koin with the latests Ktor version. (Koin-Ktor 3.2 & Ktor 2.0.1) I keep getting
KoinAppAlreadyStartedException: 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:
Copy code
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 ?