AssertionScope

The scope in which assertions are executed.

An assertion scope defines how assertion results are consumed. The default implementation throws an AssertionError when an assertion fails. Custom implementations can define different behaviour, such as collecting failures for soft assertions or adding additional context to failure messages.

This interface uses a DSL marker annotation (AssertionScope.Dsl) to prevent unwanted implicit receivers in assertion lambdas, ensuring type safety and preventing accidental calls to functions from other scopes.

Inheritors

Types

Link copied to clipboard
data class Assertion(val message: String, val cause: Throwable? = null)

Represents the result of an assertion check.

Link copied to clipboard

Default implementation of AssertionScope that throws an AssertionError when an assertion fails.

Link copied to clipboard
annotation class Dsl

DSL marker annotation to prevent unwanted implicit receivers in assertion lambdas.

Functions

Link copied to clipboard

Executes the given assertion checker and consumes its result.

Link copied to clipboard
abstract fun consumeAssertion(assertionResult: AssertionScope.Assertion)

Consumes an assertion result, typically by throwing an AssertionError if the assertion fails.

Link copied to clipboard
fun AssertionScope.fail(message: String, cause: Throwable? = null)

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

Link copied to clipboard
inline fun AssertionScope.firmly(block: context(AssertionScope) () -> Unit)
Link copied to clipboard
inline operator fun AssertionScope.invoke(block: context(AssertionScope) () -> Unit)

Invokes the given assertion block with this AssertionScope as the context receiver.

Link copied to clipboard
inline fun AssertionScope.softly(block: context(AssertionScope) () -> Unit)

Executes the given assertion block in a "soft" mode, collecting all assertion failures and reporting them together at the end.

Link copied to clipboard
inline fun AssertionScope.withClue(crossinline clue: () -> String, block: context(AssertionScope) () -> Unit)

Executes the given assertion block with a lazily-evaluated clue that is prefixed to any assertion failure messages.

inline fun AssertionScope.withClue(clue: String, block: context(AssertionScope) () -> Unit)

Executes the given assertion block with a descriptive clue that is prefixed to any assertion failure messages.