【发布时间】:2021-02-23 12:50:13
【问题描述】:
我是 kotlin 多平台库的新手。 我想做一个简单的 HTTP 获取请求并测试它是否有效。 这是我到目前为止所拥有的。 这是在 commonMain 包中
import io.ktor.client.*
import io.ktor.client.request.*
object HttpCall {
private val client: HttpClient = HttpClient()
suspend fun request(url: String): String = client.get(url)
}
这是我的测试尝试
@Test
fun should_make_http_call() {
GlobalScope.launch {
val response = HttpCall.request("https://stackoverflow.com/")
println("Response: ->$response")
assertTrue { response.contains("Stack Overflow - Where Developers Learn") }
assertTrue { response.contains("text that does not exist on stackoverflow") }
}
现在,由于第二个断言,这应该会失败,但事实并非如此。 无论我做什么,测试总是通过。 并且打印响应也不起作用 我在这里做错了什么?
【问题讨论】:
标签: unit-testing kotlin kotlin-coroutines kotlin-multiplatform