I am trying to use the interceptTestCase method to set up properties for a test case in KotlinTest as below:
class MyTest : ShouldSpec() {
private val items = mutableListOf<String>()
private var thing = 123
override fun interceptTestCase(context: TestCaseContext, test: () -> Unit) {
items.add("foo")
thing = 456
println("Before test ${items.size} and ${thing}")
test()
println("After test ${items.size} and ${thing}")
}
init {
should("not work like this") {
println("During test ${items.size} and ${thing}")
}
}
}
The output that I get is:
Before test 1 and 456
During test 0 and 123
After test 1 and 456
So the changes I have made are not visible within the test case. How should I change a property prior to each test being executed?