assertFailsWith

inline fun <T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T(source)

Asserts that a block fails with a specific exception of type T being thrown.

If the assertion fails, the specified message is used unless it is null as a prefix for the failure message.

Since Kotlin

1.0

Return

An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.


@JvmName(name = "assertFailsWithInline")
inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: () -> Unit): T(source)

Asserts that a block fails with a specific exception of type exceptionClass being thrown.

Since Kotlin

1.0

Return

An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.


@JvmName(name = "assertFailsWithInline")
inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T(source)

Asserts that a block fails with a specific exception of type exceptionClass being thrown.

If the assertion fails, the specified message is used unless it is null as a prefix for the failure message.

Since Kotlin

1.0

Return

An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.