asContextForEach
infix fun asContextForEach(content: TestFixture.Scope<suspend Value.(testExecutionScope: Test.ExecutionScope) -> Unit>.() -> Unit): TestFixture<Value>(source)
Provides a fresh value from this fixture as a context for each test declared in the content's scope.
Using this function implies a test-level fixture, whose value will be instantiated per test, and has a lifetime of that test. This is safe for concurrent test invocation, because values are isolated.
Note: As the context for tests in this scope is the fixture's value, the usual Test.ExecutionScope is unavailable as a context. Test.ExecutionScope is, however, provided as a parameter to each test.
Usage:
testFixture {
object {
var balance = 42.0
fun add(value: Double) {
balance += value
}
}
} asContextForEach {
test("add 11.0") {
add(11.0)
assertEquals(53.0, balance)
}
test("add -11.0") {
add(-11.0)
assertEquals(31.0, balance)
}
}Content copied to clipboard