Skip to content

SuiteDsl

interface SuiteDsl : PreparedDsl

A group of tests.

Example

suite("An example") {
    test("A test") {
        println("Execution")
    }

    suite("A group of tests") {
        test("First test") {
            println("Execution")
        }

        text("Second test") {
            println("Execution")
        }
    }
}

Functions

suite

abstract fun suite(
    name: String, 
    config: TestConfig = TestConfig.Empty, 
    block: SuiteDsl.() -> Unit
)

Creates a child suite named name of the current suite.

Simple example
suite("An example") {
    test("A test") {  }

    suite("A nested suite") {
        test("A nested test 1") {  }
        test("A nested test 2") {  }
    }
}
Test configuration

The default configuration for all tests can be passed with the config parameter:

suite("An example", CoroutineTimeout(2.minutes) + Tag("slow")) {
    
}

To learn more about the available configuration options, see the subtypes of TestConfig.Element.

test

abstract fun test(
    name: String, 
    config: TestConfig = TestConfig.Empty, 
    block: suspend TestDsl.() -> Unit
)

Declares a test named name as part of the current suite.

Simple example
suite("An example") {
    test("A test") {
        delay(2.minutes)          // can suspend
        time.advanceBy(2.minutes) // can control the virtual time
        launchInBackground {  }  // can start background tasks
        // …
    }
}

To learn more about the functionality available within tests, see TestDsl.

Test configuration

The test's configuration can be passed with the config parameter:

test("An example", CoroutineTimeout(2.minutes) + Tag("slow")) {
    // …
}

To learn more about the available configuration options, see the subtypes of TestConfig.Element.

open fun test(
    name: String, 
    context: CoroutineContext = EmptyCoroutineContext, 
    config: TestConfig = TestConfig.Empty, 
    block: suspend TestDsl.() -> Unit
)
Deprecated

Prefer injecting the coroutine context using the Context test configuration.

Replace with

<div class="highlight"><pre><code class="md-code__content"><span markdown>import opensavvy.prepared.suite.config.*

</span></code></pre></div>
<div class="highlight"><pre><code class="md-code__content"><span markdown>test(name, config + Context(context), block)
</span></code></pre></div>