fail

fun AssertionScope.fail(message: String, cause: Throwable? = null)(source)

Fails the current assertion scope with the given message and optional cause.

This function creates an assertion result with the provided failure message and cause, then passes it to consumeAssertion, which typically throws an AssertionError.

Receiver

The assertion scope that will consume the failure.

Parameters

message

The failure message describing what went wrong.

cause

The throwable that caused the failure, if any. Defaults to null.


@JvmName(name = "failContextual")
context(assertionScope: AssertionScope)
fun fail(message: String, cause: Throwable? = null)(source)

Fails the current assertion scope with the given message and optional cause.

This contextual version uses the assertionScope from the surrounding context. It creates an assertion result with the provided failure message and cause.

Context Parameters

assertionScope

The assertion scope that will consume the failure.

Parameters

message

The failure message describing what went wrong.

cause

The throwable that caused the failure, if any. Defaults to null.

See also