interface Builder<T> : Any

Used to construct assertions.

Fields

Name Description
abstract subject: T

Methods

assert

open fun assert(description: String, assert: AtomicAssertion.(T)->Unit): Builder<T>

Evaluates a condition that may pass or fail.

While this method can be used directly in a test but is typically used inside an extension method on Assertion.Builder such as those provided in the strikt.assertions package.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

assert: AtomicAssertion.(T)->Unit

the assertion implementation that should result in a call to Assertion.pass or Assertion.fail.

ReturnValue

Name Description
Builder<T>

this assertion builder, in order to facilitate a fluent API.

assert

abstract fun assert(description: String, expected: Any?, assert: AtomicAssertion.(T)->Unit): Builder<T>

Evaluates a condition that may pass or fail.

While this method can be used directly in a test but is typically used inside an extension method on Assertion.Builder such as those provided in the strikt.assertions package.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates. The description may contain a String.format style placeholder for the expected value.

expected: Any?

the expected value of a comparison.

assert: AtomicAssertion.(T)->Unit

the assertion implementation that should result in a call to Assertion.pass or Assertion.fail.

ReturnValue

Name Description
Builder<T>

this assertion builder, in order to facilitate a fluent API.

compose

abstract fun compose(description: String, expected: Any?, assertions: Builder<T>.(T)->Unit): CompoundAssertions<T>

Allows an assertion to be composed of multiple sub-assertions such as on fields of an object or elements of a collection.

The results of assertions made inside the assertions block are included under the overall assertion result.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

expected: Any?

the expected value of a comparison.

assertions: Builder<T>.(T)->Unit

a group of assertions that will be evaluated against the subject.

ReturnValue

Name Description
CompoundAssertions<T>

the results of assertions made inside the assertions block used to assertAll whether the overall assertion passes or fails.

compose

open fun compose(description: String, assertions: Builder<T>.(T)->Unit): CompoundAssertions<T>

Allows an assertion to be composed of multiple sub-assertions such as on fields of an object or elements of a collection.

The results of assertions made inside the assertions block are included under the overall assertion result.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

assertions: Builder<T>.(T)->Unit

a group of assertions that will be evaluated against the subject.

ReturnValue

Name Description
CompoundAssertions<T>

the results of assertions made inside the assertions block used to assertAll whether the overall assertion passes or fails.

passesIf

open fun passesIf(description: String, assert: (T)->Boolean): Builder<T>

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

assert: (T)->Boolean

a function that returns true (the assertion passes) or false (the assertion fails).

ReturnValue

Name Description
Builder<T>

this assertion builder, in order to facilitate a fluent API.

passesIf

open fun passesIf(description: String, expected: Any?, assert: (T)->Boolean): Builder<T>

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

expected: Any?

the expected value of a comparison.

assert: (T)->Boolean

a function that returns true (the assertion passes) or false (the assertion fails).

ReturnValue

Name Description
Builder<T>

this assertion builder, in order to facilitate a fluent API.

assertThat

open fun assertThat(description: String, assert: (T)->Boolean): Builder<T>

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

assert: (T)->Boolean

a function that returns true (the assertion passes) or false (the assertion fails).

ReturnValue

Name Description
Builder<T>

the chained assertion builder, in order to facilitate a fluent API.

assertThat

open fun assertThat(description: String, expected: Any?, assert: (T)->Boolean): Builder<T>

Evaluates a boolean condition. This is useful for implementing the simplest types of assertion function.

Parameters

Name Description
description: String

a description for the condition the assertion evaluates.

expected: Any?

the expected value of a comparison.

assert: (T)->Boolean

a function that returns true (the assertion passes) or false (the assertion fails).

ReturnValue

Name Description
Builder<T>

the chained assertion builder, in order to facilitate a fluent API.

get

open fun <R> get(function: T.()->R): DescribeableBuilder<R>

Maps the assertion subject to the result of function. This is useful for chaining to property values or method call results on the subject.

If function is a callable reference, (for example a getter or property reference) the subject description will be automatically determined for the returned assertion builder.

If function is a lambda, Strikt will make a best-effort attempt to determine an appropriate function / property name.

Parameters

Name Description
function: T.()->R

a lambda whose receiver is the current assertion subject.

ReturnValue

Name Description
DescribeableBuilder<R>

an assertion builder whose subject is the value returned by function.

get

abstract fun <R> get(description: String, function: T.()->R): DescribeableBuilder<R>

Maps the assertion subject to the result of function. This is useful for chaining to property values or method call results on the subject.

Parameters

Name Description
description: String

a description of the mapped result.

function: T.()->R

a lambda whose receiver is the current assertion subject.

ReturnValue

Name Description
DescribeableBuilder<R>

an assertion builder whose subject is the value returned by function.

with

abstract fun <R> with(description: String, function: T.()->R, block: Builder<R>.()->Unit): Builder<T>

Runs a group of assertions on the subject returned by function.

Parameters

Name Description
description: String

a description of the mapped result.

function: T.()->R

a lambda whose receiver is the current assertion subject.

block: Builder<R>.()->Unit

a closure that can perform multiple assertions that will all be evaluated regardless of whether preceding ones pass or fail.

ReturnValue

Name Description
Builder<T>

this builder, to facilitate chaining.

with

open fun <R> with(function: T.()->R, block: Builder<R>.()->Unit): Builder<T>

Runs a group of assertions on the subject returned by function.

Parameters

Name Description
function: T.()->R

a lambda whose receiver is the current assertion subject.

block: Builder<R>.()->Unit

a closure that can perform multiple assertions that will all be evaluated regardless of whether preceding ones pass or fail.

ReturnValue

Name Description
Builder<T>

this builder, to facilitate chaining.

chain

open fun <R> chain(function: (T)->R): DescribeableBuilder<R>

Deprecated form of with((T) -> R).

Parameters

Name Description
function: (T)->R

ReturnValue

Name Description
DescribeableBuilder<R>

chain

open fun <R> chain(description: String, function: (T)->R): DescribeableBuilder<R>

Deprecated form of with(String, (T) -> R).

Parameters

Name Description
description: String
function: (T)->R

ReturnValue

Name Description
DescribeableBuilder<R>

not

abstract fun not(): Builder<T>

Reverses any assertions chained after this method.

ReturnValue

Name Description
Builder<T>

an assertion builder that negates the results of any assertions applied to its subject.

not

abstract infix fun not(assertions: Builder<T>.()->Unit): Builder<T>

Evaluates a block of assertions on the current subject by executing them in reverse.

Parameters

Name Description
assertions: Builder<T>.()->Unit

the assertions to evaluate in reverse

ReturnValue

Name Description
Builder<T>

and

abstract infix fun and(assertions: Builder<T>.()->Unit): Builder<T>

Evaluates a block of assertions on the current subject.

The main use for this method is after strikt.assertions.isNotNull or strikt.assertions.isA in order that a group of assertions can more conveniently be performed on the narrowed subject type.

This method may be used as an infix function which tends to enhance readability when it directly follows a lambda.

Parameters

Name Description
assertions: Builder<T>.()->Unit

ReturnValue

Name Description
Builder<T>