kotest-assertions / io.kotest.assertions

Package io.kotest.assertions

Types

AssertionCounter

object AssertionCounter

ErrorCollectionMode

enum class ErrorCollectionMode

ErrorCollector

object ErrorCollector

Failures

Handles creation of errors and cleaning of stack traces.

object Failures

UserStackTraceConverter

object UserStackTraceConverter

Exceptions

MultiAssertionError

An error that bundles multiple other Throwables together

class MultiAssertionError : AssertionError

Extensions for External Classes

kotlin.collections.Iterable

Functions

asClue

Similar to withClue, but will add this as a clue to the assertion error message in case an assertion fails. Can be nested, the error message will contain all available clues.

fun <T : Any, R> T.asClue(block: (T) -> R): R

assertSoftly

Run multiple assertions and throw a single error after all are executed if any fail

fun <T> assertSoftly(assertions: () -> T): T

clueContextAsString

fun clueContextAsString(): String

collectOrThrow

If we are in "soft assertion mode" will add this throwable to the list of throwables for the current execution. Otherwise will throw immediately.

fun ErrorCollector.collectOrThrow(error: Throwable): Unit

compare

fun compare(a: Any?, b: Any?): Boolean

diffLargeString

fun diffLargeString(expected: String, actual: String, minSizeForDiff: Int): Pair<String, String>

exceptionToMessage

Returns a string error message from the given throwable. If the type is an AssertionError then the message is taken from the exceptions own message, otherwise the exception is converted to a string.

fun exceptionToMessage(t: Throwable): String

extracting

extracting pulls property values out of a list of objects for typed bulk assertions on properties.

fun <K, T> extracting(col: Collection<K>, extractor: K.() -> T): List<T>

fail

fun fail(msg: String): Nothing

getAndReset

fun AssertionCounter.getAndReset(): Int

inspecting

Inspecting allows to assert the properties of an object in a typed fashion providing a proper testing context.

fun <K> inspecting(obj: K, inspector: K.() -> Unit): Unit

log

fun log(msg: String): Unit
fun log(msg: String, t: Throwable?): Unit

retry

Retry the given lambda f in case of assertion errorAssertionError and exception Exception. Stops trying when maxRetry or timeout is reached.

suspend fun <T> retry(maxRetry: Int, timeout: Duration, delay: Duration = timeout, multiplier: Int = 1, f: () -> T): T

Retry the given lambda f in case of assertion errorAssertionError and exception of type exceptionClass. Stops trying when maxRetry or timeout is reached. Or an exception other than exceptionClass is thrown

suspend fun <T, E : Throwable> retry(maxRetry: Int, timeout: Duration, delay: Duration = timeout, multiplier: Int = 1, exceptionClass: KClass<E>, f: () -> T): T

shouldFail

Verifies that block throws an AssertionError

fun shouldFail(block: () -> Any?): AssertionError

throwCollectedErrors

The errors for the current execution are thrown as a single throwable.

fun ErrorCollector.throwCollectedErrors(): Unit

withClue

Add clue as additional info to the assertion error message in case an assertion fails. Can be nested, the error message will contain all available clues.

fun <R> withClue(clue: Any, thunk: () -> R): R