I am learning Kotlin and MockK. I have seen how to verify that a method was called and how to check the result. But how would I check, that the method has thrown an exception?
Asked
Active
Viewed 2,355 times
2 Answers
-2
This is my approach, hope its helping you
class TestClass {
fun testVerify() {
throw Exception("exception")
}
}
@Test
fun mockTest() {
try {
TestClass().testVerify()
}
catch (e: Exception) {
assertEquals(e.message, "exception")
}
}

Đàm Tùng
- 329
- 1
- 3
- 7