最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

kotlin - Test refactoring when migrating ktor 2.x to 3.x - Stack Overflow

programmeradmin4浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论