找不到Kotlin测试,但有时只有
这是我想运行的测试:
@Test
fun testRequestFails() = runBlocking {
assertFailsWith(ClientRequestException::class) {
val result = httpClient.get<MyResponse>("$baseUrl/some/req/that/should/fail") {
header(API_KEY_HEADER, testApiKey)
}
}
}
httpclient.get
是暂停FUN
。当我尝试使用./ gradlew Test
或IDEA中运行此操作时,测试被默默跳过!当我尝试在想法中专门运行这个问题时,它说“没有找到给定的测试。”
然而!我可以通过将assertfailswith
的结果分配给变量,或者通过将assertequals(1,1)
添加到测试结束时,可以找到它。
我可能在Coroutines上做错了什么,但是在我的脑海中,如果我写了一个错误的测试,那应该是 fail ,而不是 消失
它是深层的令人不安的是,测试可能会消失而不会警告!
- 是否有办法确保可以发现测试,而无需进行无用的变量分配或无用的断言?
- 如果测试未能发现,有没有办法使巨大的警钟消失?
build.gradle.kts的摘要:
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
dependencies {
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
}
Here is the test that I'd like to run:
@Test
fun testRequestFails() = runBlocking {
assertFailsWith(ClientRequestException::class) {
val result = httpClient.get<MyResponse>("$baseUrl/some/req/that/should/fail") {
header(API_KEY_HEADER, testApiKey)
}
}
}
httpClient.get
is a suspend fun
. When I try to run this with ./gradlew test
or IDEA, the test is silently skipped! When I try to run this one specifically in IDEA, it says "No tests found for given includes."
However! I can make it findable and runnable by either assigning the result of assertFailsWith
to a variable, or by adding assertEquals(1,1)
to the end of the test.
I'm probably doing something wrong with coroutines, but in my head, if I write a test wrong, it should fail, not disappear
It's deeply troubling that a test can disappear without warning!
- Is there a way to ensure the test is discoverable, without doing a useless variable assignment or a useless assert?
- Is there a way to make giant alarm bells go off if a test fails to get discovered?
Snippets from build.gradle.kts:
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
dependencies {
testImplementation(kotlin("test-junit5"))
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
testImplementation("io.ktor:ktor-server-tests:$ktorVersion")
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论