admin管理员组

文章数量:1400007

I'm having a special case when trying to migrate from ktor 2.x to 3.x. We have a helper class for backend tests and mainly its one function is used a lot. Here's the code for it:

        private val customApplicationEnvironment =
            applicationEngineEnvironment {
                config = testEnvironmentConfig()
                log = LoggerFactory.getLogger("ktor.test")
            }

        fun <R> testApp(test: TestApplicationEngine.() -> R): R {
            customApplicationEnvironment.start()
            val engine = TestApplicationEngine(customApplicationEnvironment) {}
            engine.start()
            try {
                return engine.test()
            } finally {
                engine.stop(0L, 0L)
                customApplicationEnvironment.stop()
            }
        }

Otherwise its pretty clear to me, but how can I initialize TestApplicationEngine with ktor 3.x as it needs Application, Events etc?

本文标签: kotlinTest refactoring when migrating ktor 2x to 3xStack Overflow