assertk / assertk

Package assertk

Types

(common, jvm)

Assert

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

sealed class Assert<out T>
(common, jvm)

AssertBlock

typealias AssertBlock<T> = Assert<Result<T>>
(common, jvm)

Result

sealed class Result<out T>
(common, jvm)

Table

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

sealed class Table
(common, jvm)

Table1

A table with rows of 1 value.

class Table1<C1> : Table
(common, jvm)

Table1Builder

Builds a table with the given rows.

class Table1Builder : TableBuilder
(common, jvm)

Table2

A table with rows of 2 values.

class Table2<C1, C2> : Table
(common, jvm)

Table2Builder

Builds a table with the given rows.

class Table2Builder : TableBuilder
(common, jvm)

Table3

A table with rows of 3 values.

class Table3<C1, C2, C3> : Table
(common, jvm)

Table3Builder

Builds a table with the given rows.

class Table3Builder : TableBuilder
(common, jvm)

Table4

A table with rows of 4 values.

class Table4<C1, C2, C3, C4> : Table
(common, jvm)

Table4Builder

Builds a table with the given rows.

class Table4Builder : TableBuilder
(common, jvm)

TableBuilder

Builds a table with the given rows.

sealed class TableBuilder
(common, jvm)

ThreadLocalRef

open class ThreadLocalRef<T>

Annotations

(common, jvm)

AssertkDsl

Marks the assertion DSL.

annotation class AssertkDsl
(common, jvm)

PlatformName

Allows to resolve name conflicts from common modules.

annotation class PlatformName

Properties

(common, jvm)

value

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

Functions

(common, jvm)

all

All assertions in the given lambda are run.

fun <T> Assert<T>.all(message: String, body: Assert<T>.() -> Unit): Unit
fun <T> Assert<T>.all(body: Assert<T>.() -> Unit): Unit
(common, jvm)

assertAll

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

fun assertAll(f: () -> Unit): Unit
(common, jvm)

assertThat

Asserts on the given value with an optional name.

fun <T> assertThat(actual: 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(getter: KProperty0<T>, name: String? = null): Assert<T>

Asserts on the given block returning an Assert<Result<T>>. You can test that it returns a value or throws an exception.

fun <T> assertThat(f: () -> T): Assert<Result<T>>
(common, jvm)

catch

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

fun catch(f: () -> Unit): Throwable?
(common, jvm)

doesNotThrowAnyException

fun <T> Assert<Result<T>>.doesNotThrowAnyException(): Unit

fail

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

(common) fun fail(error: AssertionError): Nothing
(jvm) fun fail(error: AssertionError): Nothing

Fail the test with the given message.

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

notifyFailure

fun notifyFailure(e: Throwable): Unit
(common, jvm)

returnedValue

Runs the given lambda if the block returns a value, otherwise fails.

fun <T> Assert<Result<T>>.returnedValue(f: Assert<T>.() -> Unit): Unit
(common, jvm)

tableOf

Builds a table with the given column names.

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
(common, jvm)

thrownError

Runs the given lambda if the block throws an error, otherwise fails.

fun <T> Assert<Result<T>>.thrownError(f: Assert<Throwable>.() -> Unit): Unit