data class TestCase
A TestCase describes an actual block of code that will be tested. It contains a reference back to the Spec instance in which it is being executed.
It also captures a closure of the body of the test case. This is a function which is invoked with a TestContext. The context is used so that the test function can, at runtime, register nested tests with the test engine. This allows nested tests to be executed lazily as required, rather than when the Spec instance is created.
A test can be nested inside other tests if the Spec supports it.
For example, in the FunSpec we only allow top level tests.
test("this is a test") { }
And in WordSpec we allow two levels of tests.
"a string" should { "return the length" { } }
<init> |
A TestCase describes an actual block of code that will be tested. It contains a reference back to the Spec instance in which it is being executed. TestCase(description: Description, spec: Spec, test: suspend TestContext.() -> Unit, source: SourceRef, type: TestType, config: TestCaseConfig = TestCaseConfig(), factoryId: TestFactoryId? = null, assertionMode: AssertionMode? = null) |
assertionMode |
val assertionMode: AssertionMode? |
config |
val config: TestCaseConfig |
description |
val description: Description |
factoryId |
val factoryId: TestFactoryId? |
name |
val name: String |
source |
val source: SourceRef |
spec |
val spec: Spec |
test |
val test: suspend TestContext.() -> Unit |
type |
val type: TestType |
getLine |
fun getLine(): Int |
isTopLevel |
fun isTopLevel(): Boolean |
container |
Creates a TestCase of type TestType.Container, with default config, and derived source ref. fun container(description: Description, spec: Spec, test: suspend TestContext.() -> Unit): TestCase |
test |
Creates a TestCase of type TestType.Test, with default config, and derived source ref. fun test(description: Description, spec: Spec, test: suspend TestContext.() -> Unit): TestCase |
extensions |
Returns the runtime resolved TestCaseExtensions applicable for this TestCase. Those are extensions registered on the test case's own config, those registered on the spec instance, and those registered at the project level. fun TestCase.extensions(): List<TestCaseExtension> |
invokeAfterInvocation |
suspend fun TestCase.invokeAfterInvocation(k: Int): Unit |
invokeAfterTest |
suspend fun TestCase.invokeAfterTest(result: TestResult): Try<TestCase> |
invokeBeforeInvocation |
suspend fun TestCase.invokeBeforeInvocation(k: Int): Unit |
invokeBeforeTest |
Invokes the beforeTest callbacks for this test, taking the listeners from those present at the spec level and the project level. suspend fun TestCase.invokeBeforeTest(): Try<TestCase> |
isActive |
Returns true if the given TestCase is active. fun TestCase.isActive(): Boolean |
isBang |
Returns true if this test is disabled by being prefixed with a ! fun TestCase.isBang(): Boolean |
isFocused |
Returns true if this test is a focused test. That is, if the name starts with "f:". fun TestCase.isFocused(): Boolean |