我正在学习Kotlin和MockK。我已经看到了如何验证方法是否被调用,以及如何检查结果。但是我该如何检查该方法是否抛出了异常呢?
发布于 2020-12-01 17:15:39
对不起,我找到了:assertFailsWith<EceptionClass> { methodCall() }
发布于 2021-02-04 10:28:49
这就是我的方法,希望能对你有所帮助
class TestClass {
fun testVerify() {
throw Exception("exception")
}
}@Test
fun mockTest() {
try {
TestClass().testVerify()
}
catch (e: Exception) {
assertEquals(e.message, "exception")
}
}https://stackoverflow.com/questions/65087594
复制相似问题