checkThrows
Verifies that block throws an exception of type T.
If block indeed throws an exception of type T, it is returned. In all other cases, an AssertionError is thrown.
Example
checkThrows<IllegalStateException> {
yourService()
}
Content copied to clipboard
If the expected exception is thrown, it is returned by the function, so you can write further assertions. For example, if you want an exception with a specific message, write:
val e = checkThrows<IllegalStateException> {
yourService()
}
check(e.message = "Cannot create a new user because another one already exists")
Content copied to clipboard