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

Spec

abstract class Spec : TestConfiguration, SpecCallbackMethods

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?

rootTestCases

Contains the root TestCases used in this spec.

var rootTestCases: List<TestCase>

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

addRootTestCase

Adds a new root-level TestCase to this Spec.

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

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

Extension Functions

autoClose

Register an AutoCloseable so that it's close methods is automatically invoked when the tests are completed.

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

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>

materializeRootTests

Returns the root tests from this Spec and any included factories. The returned list will be ordered according to the TestCaseOrder returned by project config, or if not defined, the kotest default.

fun Spec.materializeRootTests(): List<RootTest>

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

BehaviorSpec

abstract class BehaviorSpec : Spec, BehaviorSpecDsl

CompositeSpec

abstract class CompositeSpec : Spec

DescribeSpec

abstract class DescribeSpec : Spec, DescribeSpecDsl

ExpectSpec

abstract class ExpectSpec : Spec, ExpectSpecDsl

FeatureSpec

abstract class FeatureSpec : Spec, FeatureSpecDsl

FreeSpec

abstract class FreeSpec : Spec, FreeSpecDsl

FunSpec

abstract class FunSpec : Spec, FunSpecDsl

ShouldSpec

abstract class ShouldSpec : Spec, ShouldSpecDsl

StringSpec

abstract class StringSpec : Spec, StringSpecDsl

WordSpec

abstract class WordSpec : Spec, WordSpecDsl