Skip to content

Suiteopensavvy.prepared.suiteTestDsl

TestDsl

interface TestDsl : PreparedDsl

A test declaration.

This interface is most often used as a test declaration: suspend TestDsl.() -> Unit.

Tests allow to control the time. For more information, read time.

Design notes

It is our goal to keep this interface as lightweight as possible, because any field we add here risks being shadowed by local variables in the tests.

For example, if we were to add a member called foo, then this code…

test("Test") {
    val foo = 
}

…shadows the member 'foo'.

Instead, we add all fields to TestEnvironment, and create extension functions which expose the most important functionality.

Note to runner implementors

If you are implementing your own test runner, you will need to provide an instance of this interface. Because it encapsulates the whole test machinery, we recommend using runTestDsl instead of making your own implementation.

See also

  • cleanUpRegister a finalizer which is executed at the end of the test

Properties

backgroundScope

CoroutineScope for services started by this test.

environment

Metadata about the running test.

foregroundScope

CoroutineScope for tasks started by this test.

Random

@get:
JvmName
(name = "getKotlinRandom")val TestDsl.Random: Random

See random.

random

Random generator control center.

time

Time control center.

Functions

cleanUp

suspend fun TestDsl.cleanUp(name: String, onSuccess: Boolean = true, onFailure: Boolean = true, block: suspend TestDsl.() -> Unit)

Registers a block named name to run at the end of the test.

immediate

open suspend fun <T> PreparedProvider<T>.immediate(name: String = "Immediate value #"): T

Realizes a Prepared value from the provided PreparedProvider.

invoke

open suspend operator fun <T> Prepared<T>.invoke(): T

Realizes a Prepared value in the context of this test.

launch

fun TestDsl.launch(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Starts a task in the foregroundScope. The test will wait for this task before finishing.

launchInBackground

fun TestDsl.launchInBackground(context: CoroutineContext = EmptyCoroutineContext, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): Job

Starts a task in the backgroundScope scope. The test will not wait for this task before finishing.