assertk

Package assertk

Types

Assert
(Common)

sealed class Assert<out T>

An assertion. Holds an actual value to assertion on and an optional name.

AssertBlock
(Common)

sealed class AssertBlock<out T>

An assertion on a block of code. Can assert that it either throws and error or returns a value.

FailingAssert
(Common)

class FailingAssert<out T> : Assert<T>

Table
(Common)

sealed class Table

A table of rows to assert on. This makes it easy to run the same assertions are a number of inputs and outputs.

Table1
(Common)

class Table1<C1> : Table

A table with rows of 1 value.

Table1Builder
(Common)

class Table1Builder : TableBuilder

Builds a table with the given rows.

Table2
(Common)

class Table2<C1, C2> : Table

A table with rows of 2 values.

Table2Builder
(Common)

class Table2Builder : TableBuilder

Builds a table with the given rows.

Table3
(Common)

class Table3<C1, C2, C3> : Table

A table with rows of 3 values.

Table3Builder
(Common)

class Table3Builder : TableBuilder

Builds a table with the given rows.

Table4
(Common)

class Table4<C1, C2, C3, C4> : Table

A table with rows of 4 values.

Table4Builder
(Common)

class Table4Builder : TableBuilder

Builds a table with the given rows.

TableBuilder
(Common)

sealed class TableBuilder

Builds a table with the given rows.

ThreadLocalRef
(Common)

open expect class ThreadLocalRef<T>

ValueAssert
(Common)

class ValueAssert<out T> : Assert<T>

Annotations

AssertkDsl
(Common)

annotation class AssertkDsl

Marks the assertion DSL.

PlatformName

annotation expect class PlatformName

Allows to resolve name conflicts from common modules.

Type Aliases

ThreadLocalRef
(JVM)

actual typealias ThreadLocalRef<T> = ThreadLocal<T>

Properties

value
(Common)

var <T> ThreadLocalRef<T>.value: T?

Functions

all
(Common)

fun <T> Assert<T>.all(message: String = SoftFailure.defaultMessage, body: Assert<T>.() -> Unit): Unit

All assertions in the given lambda are run.

assert
(Common)

fun <T> assert(actual: T, name: String? = null): Assert<T>

Asserts on the given value with an optional name.

fun <T> assert(f: () -> T): AssertBlock<T>

Asserts on the given block. You can test that it returns a value or throws an exception.

assertAll
(Common)

fun assertAll(f: () -> Unit): Unit

Runs all assertions in the given lambda and reports any failures.

assertThat
(Common)

fun <T> assertThat(actual: T, name: String? = null): Assert<T>

Asserts on the given value with an optional name.

fun <T> assertThat(getter: KProperty0<T>, name: String? = null): Assert<T>

Asserts on the given property reference using its name, if no explicit name is specified. This method should be preferred in cases, where property references can be used, as it uses the property's name for the assertion automatically. The name may optionally be overridden, if needed.

fun <T> assertThat(f: () -> T): AssertBlock<T>

Asserts on the given block. You can test that it returns a value or throws an exception.

catch
(Common)

fun catch(f: () -> Unit): Throwable?

Catches any exceptions thrown in the given lambda and returns it. This is an easy way to assert on expected thrown exceptions.

fail
(Common)

fun fail(error: AssertionError): Nothing

Fail the test with the given {@link AssertionError}.

fun fail(message: String, expected: Any? = NONE, actual: Any? = NONE): Nothing

Fail the test with the given message.

notifyFailure
(Common)

fun notifyFailure(e: Throwable): Unit

tableOf
(Common)

fun tableOf(name1: String): Table1Builder
fun tableOf(name1: String, name2: String): Table2Builder
fun tableOf(name1: String, name2: String, name3: String): Table3Builder
fun tableOf(name1: String, name2: String, name3: String, name4: String): Table4Builder

Builds a table with the given column names.