toThrow

context(assertionScope: AssertionScope)
inline fun Expect.Companion.toThrow(crossinline block: () -> Unit)(source)(source)

Asserts that the given block throws an exception.

If the block completes without throwing an exception, the assertion fails with a message indicating that no exception was thrown. Any exception thrown by the block causes the assertion to pass.

Context Parameters

assertionScope

The assertion scope that will consume the assertion result.

Parameters

block

The code block that should throw an exception. Called exactly once.


@JvmName(name = "orThrowCheckingType")
context(assertionScope: AssertionScope)
inline fun <ThrowableType : Throwable> Expect.Companion.toThrow(crossinline block: () -> Unit)(source)(source)

Asserts that the given block throws an exception of the specified type ThrowableType.

If the block completes without throwing an exception, the assertion fails with a message indicating that no exception was thrown. If the block throws an exception of the wrong type, the assertion fails with a message indicating the type mismatch.

Context Parameters

assertionScope

The assertion scope that will consume the assertion result.

Parameters

block

The code block that should throw an exception of type ThrowableType. Called exactly once.

Type Parameters

ThrowableType

The expected type of the exception. The exception must be an instance of this type.


context(assertionScope: AssertionScope)
inline fun Expect.Companion.toThrow(crossinline block: () -> Unit, checker: Expect<Throwable>.() -> Unit)(source)

Asserts that the given block throws an exception, and if it does, asserts on the thrown exception using the provided checker.

If the block completes without throwing an exception, the assertion fails with a message indicating that no exception was thrown. If the block throws an exception, it is passed to the checker for further assertions.

Context Parameters

assertionScope

The assertion scope that will consume the assertion result.

Parameters

block

The code block that should throw an exception. Called exactly once.

checker

The assertion block to execute on the thrown exception.


@JvmName(name = "orThrowCheckingType")
context(assertionScope: AssertionScope)
inline fun <ThrowableType : Throwable> Expect.Companion.toThrow(crossinline block: () -> Unit, checker: Expect<ThrowableType>.() -> Unit)(source)

Asserts that the given block throws an exception of the specified type ThrowableType, and if it does, asserts on the thrown exception using the provided checker.

If the block completes without throwing an exception, the assertion fails with a message indicating that no exception was thrown. If the block throws an exception of the wrong type, the assertion fails with a message indicating the type mismatch. If the block throws an exception of the correct type, it is passed to the checker for further assertions.

Context Parameters

assertionScope

The assertion scope that will consume the assertion result.

Parameters

block

The code block that should throw an exception of type ThrowableType. Called exactly once.

checker

The assertion block to execute on the thrown exception if it is of the expected type.

Type Parameters

ThrowableType

The expected type of the exception. The exception must be an instance of this type.