Package kotlin.test

Types

Asserter

interface Asserter

Abstracts the logic for performing assertions. Specific implementations of Asserter can use JUnit or TestNG assertion facilities.

AsserterContributor

interface AsserterContributor

Checks applicability and provides Asserter instance

DefaultAsserter

class DefaultAsserter : Asserter

Default Asserter implementation to avoid dependency on JUnit or TestNG.

QUnitAsserter

class QUnitAsserter

Properties

asserter

val asserter: Asserter

Current adapter providing assertion implementations

Functions

assertEquals

fun <T> assertEquals(
    expected: T,
    actual: T,
    message: String? = null
): Unit

Asserts that the expected value is equal to the actual value, with an optional message.

assertFails

fun assertFails(block: () -> Unit): Throwable
fun assertFails(
    message: String?,
    block: () -> Unit
): Throwable

Asserts that given function block fails by throwing an exception.

assertFailsWith

fun <T : Throwable> assertFailsWith(
    message: String? = null,
    block: () -> Unit
): T

Asserts that a block fails with a specific exception of type T being thrown. Since inline method doesn't allow to trace where it was invoked, it is required to pass a message to distinguish this method call from others.

fun <T : Throwable> assertFailsWith(
    exceptionClass: KClass<T>,
    block: () -> Unit
): T
header fun <T : Throwable> assertFailsWith(
    exceptionClass: KClass<T>,
    message: String?,
    block: () -> Unit
): T

Asserts that a block fails with a specific exception of type exceptionClass being thrown.

assertFalse

fun assertFalse(
    message: String? = null,
    block: () -> Boolean
): Unit

Asserts that the given block returns false.

fun assertFalse(
    actual: Boolean,
    message: String? = null
): Unit

Asserts that the expression is false with an optional message.

assertNotEquals

fun <T> assertNotEquals(
    illegal: T,
    actual: T,
    message: String? = null
): Unit

Asserts that the actual value is not equal to the illegal value, with an optional message.

assertNotNull

fun <T : Any> assertNotNull(
    actual: T?,
    message: String? = null
): T

Asserts that the actual value is not null, with an optional message.

fun <T : Any, R> assertNotNull(
    actual: T?,
    message: String? = null,
    block: (T) -> R
): Unit

Asserts that the actual value is not null, with an optional message and a function block to process the not-null value.

assertNull

fun assertNull(actual: Any?, message: String? = null): Unit

Asserts that the actual value is null, with an optional message.

assertTrue

fun assertTrue(
    message: String? = null,
    block: () -> Boolean
): Unit

Asserts that the given block returns true.

fun assertTrue(
    actual: Boolean,
    message: String? = null
): Unit

Asserts that the expression is true with an optional message.

currentStackTrace

fun currentStackTrace(): Array<StackTraceElement>

Returns an array of stack trace elements, each representing one stack frame. The first element of the array (assuming the array is not empty) represents the top of the stack, which is the place where currentStackTrace function was called from.

expect

fun <T> expect(expected: T, block: () -> T): Unit

Asserts that given function block returns the given expected value.

fun <T> expect(
    expected: T,
    message: String?,
    block: () -> T
): Unit

Asserts that given function block returns the given expected value and use the given message if it fails.

fail

fun fail(message: String? = null): Nothing

Marks a test as having failed if this point in the execution path is reached, with an optional message.

todo

header fun todo(block: () -> Unit): Unit

Comments out a block of test code until it is implemented while keeping a link to the code to implement in your unit test output