kotest-core / io.kotest.core.spec / Spec

Spec

abstract class Spec : TestConfiguration, SpecConfigurationMethods

Constructors

<init>

Spec()

Properties

isolation

Sets the IsolationMode used by the test engine when running tests in this spec. If left null, then the project default is applied.

var isolation: IsolationMode?

testOrder

Sets the TestCaseOrder to control the order of execution of root level tests in this spec. If left null, then the project default is applied.

var testOrder: TestCaseOrder?

Functions

afterTest

Registers a new after-test callback to be executed after every TestCase. The callback provides two parameters - the test case that has just completed, and the TestResult outcome of that test.

open fun afterTest(f: AfterTest): Unit

beforeTest

Registers a new before-test callback to be executed before every TestCase. The TestCase about to be executed is provided as the parameter.

open fun beforeTest(f: BeforeTest): Unit

javascriptTestInterceptor

The annotation JsTest is intercepted by the kotlin.js compiler and invoked in the generated javascript code. We need to hook into this function to invoke our execution code which will run tests defined by kotest.

fun javascriptTestInterceptor(): Unit

materializeRootTests

Materializes the tests defined in this spec as TestCase instances.

abstract fun materializeRootTests(): List<TestCase>

rootTests

Returns the root tests of this spec.

fun rootTests(): List<RootTest>

Extension Functions

autoClose

Closes an AutoCloseable when the spec is completed by registering an afterSpec listener which invokes the AutoCloseable.close method.

fun <T : AutoCloseable> TestConfiguration.autoClose(closeable: T): T

Closes a lazy AutoCloseable when the spec is completed by registering an afterSpec listener which invokes the AutoCloseable.close method.

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

createTestCase

fun Spec.createTestCase(name: String, test: suspend TestContext.() -> Unit, config: TestCaseConfig, type: TestType): TestCase

focusTests

Returns the focused root tests for this Spec. A focused test is one whose name begins with "f:".

fun Spec.focusTests(): List<TestCase>

invokeAfterSpec

Notifies the user listeners that a Spec has finished. This will be invoked for every instance of a spec.

suspend fun Spec.invokeAfterSpec(): Try<Spec>

invokeBeforeSpec

Notifies the user listeners that a Spec is starting. This will be invoked for every instance of a spec.

suspend fun Spec.invokeBeforeSpec(): Try<Spec>

resolvedAssertionMode

fun Spec.resolvedAssertionMode(): AssertionMode

resolvedExtensions

fun Spec.resolvedExtensions(): List<Extension>

resolvedIsolationMode

fun Spec.resolvedIsolationMode(): IsolationMode

resolvedTestCaseOrder

fun Spec.resolvedTestCaseOrder(): TestCaseOrder

resolvedTestListeners

Returns the resolved listeners for a given Spec. That is, the listeners defined directly on the spec, listeners generated from the callback-dsl methods, and listeners defined in any included test factories.

fun Spec.resolvedTestListeners(): List<TestListener>

tempfile

fun TestConfiguration.tempfile(prefix: String? = null, suffix: String? = ".tmp"): File

Inheritors

AnnotationSpec

abstract class AnnotationSpec : Spec

CompositeSpec

abstract class CompositeSpec : Spec

DslDrivenSpec

abstract class DslDrivenSpec : Spec