AssertJ:类型推断失败:没有足够的信息来推断 org.assertj.core.api.Assertions.fail 中的参数 T
AssertJ: Type inference failed: Not enough information to infer parameter T in org.assertj.core.api.Assertions.fail
在纯 Kotlin 项目中,我使用 JUnit Jupiter 5.5.2 和 AssertJ 3.10.0。以下测试执行成功:
@Test
fun `Validates something`() = runBlocking {
try {
// Assert something
} catch (t: Throwable) {
fail("Should not throw $t")
}
}
更新到 AssertJ 3.11.1 后,测试构建失败并显示此消息:
Type inference failed: Not enough information to infer parameter T in fun fail(p0: String!): T!
Please specify it explicitly.
如果我使用 fail<Nothing>("Should not throw $t")
那么 No test were found
.
我试图弄清楚发生了什么 - 但没有成功。
相关
问题似乎出在 runBlocking
表达式正文上。如果你把它变成一个块体,那么无论你在fail
方法上指定哪种类型它都会起作用(以Nothing
为例,可以是Any
,Any?
或任何其他类型):
@Test
fun `Validates something`() {
runBlocking {
try {
// Assert something
} catch (t: Throwable) {
fail<Nothing>("Should not throw $t")
}
}
}
在纯 Kotlin 项目中,我使用 JUnit Jupiter 5.5.2 和 AssertJ 3.10.0。以下测试执行成功:
@Test
fun `Validates something`() = runBlocking {
try {
// Assert something
} catch (t: Throwable) {
fail("Should not throw $t")
}
}
更新到 AssertJ 3.11.1 后,测试构建失败并显示此消息:
Type inference failed: Not enough information to infer parameter T in fun fail(p0: String!): T!
Please specify it explicitly.
如果我使用 fail<Nothing>("Should not throw $t")
那么 No test were found
.
我试图弄清楚发生了什么 - 但没有成功。
相关
问题似乎出在 runBlocking
表达式正文上。如果你把它变成一个块体,那么无论你在fail
方法上指定哪种类型它都会起作用(以Nothing
为例,可以是Any
,Any?
或任何其他类型):
@Test
fun `Validates something`() {
runBlocking {
try {
// Assert something
} catch (t: Throwable) {
fail<Nothing>("Should not throw $t")
}
}
}