kotest-assertions / io.kotest.assertions.throwables / shouldNotThrowExactlyUnit

shouldNotThrowExactlyUnit

inline fun <reified T : Throwable> shouldNotThrowExactlyUnit(block: () -> Unit): Unit

Verifies that a block of code doesn't throw a Throwable of type T, not including subclasses of T

Use this function to wrap a block of code that you'd like to verify whether it throws T (not including) or not. If T is thrown, this will thrown an AssertionError. If anything else is thrown, the throwable will be propagated. This is done so that no unexpected error is silently ignored.

This should be used when shouldNotThrowExactly can't be used, such as when doing assignments (assignments are statements, therefore has no return value).

This function won't include subclasses of T. For example, if you test for java.io.IOException and the code block throws java.io.FileNotFoundException, propagate the java.io.FileNotFoundException instead of wrapping it in an AssertionError.

If you wish to test T and subclasses, use shouldNotThrowUnit.

If you don't care about the thrown exception, use shouldNotThrowAnyUnit

See Also

shouldNotThrowExactly