【发布时间】:2021-06-18 21:33:55
【问题描述】:
我的主要是这样的
suspend fun main(testing: Boolean = false) {
// do some db related stuff with coroutines
dbSetupRun() // this is using coroutines
embeddedServer(Netty, 8080) {
...
}.start(wait = true}
我的测试代码看起来像
@Test
suspend fun `test` () {
withTestApplication({ main(testing = true) }) {
handleRequest(HttpMethod.Get, "${config.root}/${config.version}/test").apply {
assertEquals(HttpStatusCode.OK, response.status())
assertEquals(response, content)
}
但我收到一条错误消息,指出该代码的 Suspend function 'main' should be called only from a coroutine or another suspend function
很困惑我应该如何处理这个
【问题讨论】:
-
TestApplication 有什么用?
-
这是我一直用于测试应用程序的 Ktor 函数 api.ktor.io/0.9.5/io.ktor.server.testing/…
-
看起来它不支持挂起功能。为什么你的主要暂停?
标签: kotlin kotlin-coroutines ktor