I am trying to use the interceptTestCase method to set properties for a test case in KotlinTest , as shown 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 I get is:
Before test 1 and 456
During test 0 and 123
After tests 1 and 456
So, the changes I made are not displayed in the test case. How do I change a property before each test run?
source
share