Search code examples
kotlinktorkoin

Test koin in ktor application


Hi im trying to write ktor testcases with koin dependency injection and in the tutorial im watching the person uses withTestApplication(moduleFunction = {install(Routing)}) Though withTestApplication() is deprecated and so the moduleFunction part does not work with the new testApplication() setup what should i do instead is my question? this is the tutorial im watching Tutorial i have also checked

https://ktor.io/docs/migrating-2.html#testing-api

and

https://insert-koin.io/docs/reference/koin-test/testing


Solution

  • To configure a module using testApplication use the application method:

    import io.ktor.server.application.*
    import io.ktor.server.routing.*
    import io.ktor.server.testing.*
    import kotlin.test.Test
    
    class KtorTest {
        @Test
        fun test() = testApplication {
            application {
                install(Routing)
            }
        }
    }