Skip to content

PreparedSpec

abstract class PreparedSpec(body: PreparedSpec.() -> Unit, config: TestConfig = TestConfig.Empty) : AbstractSpec, SuiteDsl

Declares a Prepared test suite using the Kotest framework.

Install the Kotest IntelliJ plugin to have gutter icons to run a specific test.

Example

class MyTest : PreparedSpec({
    test("A regular test") {
        // …
    }

    suite("A suite") {
        test("Another test") {
            // …
        }
    }
})

Constructors

PreparedSpec

constructor(body: PreparedSpec.() -> Unit, config: TestConfig = TestConfig.Empty)

Properties

assertionMode

var assertionMode: AssertionMode?

assertions

var assertions: AssertionMode?

assertSoftly

blockingTest

coroutineDebugProbes

coroutineDispatcherFactory

var coroutineDispatcherFactory: CoroutineDispatcherFactory?

coroutineTestScope

defaultTestConfig

var defaultTestConfig: DefaultTestConfig?

duplicateTestNameMode

var duplicateTestNameMode: DuplicateTestNameMode?

extensions

open val extensions: List<Extension>

failfast

invocationTimeout

isolationMode

var isolationMode: IsolationMode?

metadata

val metadata: TestMetadata

nonDeterministicTestVirtualTimeEnabled

retries

var retries: Int?

retryDelay

scope

@ExperimentalKotest
@KotestInternal
lateinit var scope: CoroutineScope

severity

var severity: TestCaseSeverityLevel?

testCaseOrder

var testCaseOrder: TestCaseOrder?

testExecutionMode

var testExecutionMode: TestExecutionMode?

testOrder

var testOrder: TestCaseOrder?

timeout

var timeout: Long?

Functions

add

open override fun add(test: RootTest)
open override fun add(test: TestDefinition)

afterAny

fun afterAny(f: AfterAny)
open suspend fun afterAny(testCase: TestCase, result: TestResult)

afterContainer

fun afterContainer(f: AfterContainer)
open suspend fun afterContainer(testCase: TestCase, result: TestResult)

afterEach

fun afterEach(f: AfterEach)
open suspend fun afterEach(testCase: TestCase, result: TestResult)

afterInvocation

fun afterInvocation(f: AfterInvocation)

afterProject

fun afterProject(f: AfterProject)

afterSpec

open suspend fun afterSpec(spec: Spec)
override fun afterSpec(f: AfterSpec)

afterTest

override fun afterTest(f: AfterTest)
open suspend fun afterTest(testCase: TestCase, result: TestResult)

aroundTest

fun aroundTest(aroundTestFn: AroundTestFn)

assertionMode

open fun assertionMode(): AssertionMode?

autoClose

fun <T : AutoCloseable> autoClose(closeable: T): T
fun <T : AutoCloseable> autoClose(closeable: Lazy<T>): Lazy<T>

autoCloseables

fun autoCloseables(): List<Lazy<AutoCloseable>>

beforeAny

fun beforeAny(f: BeforeAny)
open suspend fun beforeAny(testCase: TestCase)

beforeContainer

fun beforeContainer(f: BeforeContainer)
open suspend fun beforeContainer(testCase: TestCase)

beforeEach

fun beforeEach(f: BeforeEach)
open suspend fun beforeEach(testCase: TestCase)

beforeInvocation

fun beforeInvocation(f: BeforeInvocation)

beforeSpec

fun beforeSpec(f: BeforeSpec)
open suspend fun beforeSpec(spec: Spec)

beforeTest

open suspend fun beforeTest(testCase: TestCase)
override fun beforeTest(f: BeforeTest)

coroutineDispatcherFactory

open fun coroutineDispatcherFactory(): CoroutineDispatcherFactory?

duplicateTestNameMode

open fun duplicateTestNameMode(): DuplicateTestNameMode?

extension

fun extension(f: TestCaseExtensionFn)
fun <T : Extension> extension(extension: T): T

extensions

fun extensions(): List<Extension>
fun extensions(extensions: List<Extension>)
fun extensions(vararg extensions: Extension)

finalizeSpec

fun finalizeSpec(f: FinalizeSpec)

include

fun include(factory: TestFactory)
fun include(prefix: String, factory: TestFactory)

invocationTimeout

open fun invocationTimeout(): Long?

isolationMode

open fun isolationMode(): IsolationMode?

preparedSuite

fun AbstractSpec.preparedSuite(config: TestConfig = TestConfig.Empty, block: KotestSuiteDsl.() -> Unit)

Executes a Prepared SuiteDsl in an existing Kotest suite.

To create a Prepared-specific suite, see PreparedSpec.

Example

This example uses StringSpec, but tests can be registered using any spec.

class MyTests : StringSpec({
    "A regular Kotest test" {
        // …
    }

    preparedSuite {
        test("A regular Prepared test") {
            // …
        }

        suite("A regular Prepared test suite") {
            // …
        }
    }
})

register

fun <T : Extension> register(extension: T): T

registeredAutoCloseables

fun registeredAutoCloseables(): List<Lazy<AutoCloseable>>

suite

@JvmName(name = "suiteKotest")
fun suite(
    name: String, 
    config: TestConfig = TestConfig.Empty, 
    block: KotestSuiteDsl.() -> 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.

tags

open override fun tags(vararg tags: Tag)
open fun tags(): Set<Tag>

test

open override fun test(
    name: String, 
    config: TestConfig, 
    block: suspend TestDsl.() -> Unit
)

testCaseOrder

open fun testCaseOrder(): TestCaseOrder?

testExecutionMode

open fun testExecutionMode(): TestExecutionMode?

tests

open override fun tests(): List<TestDefinition>

timeout

open fun timeout(): Long?