I'm trying to do a standard beforeAll
/afterAll
type setup in the unit tests, but am having some problems. It seems like the interceptSpec
functionality is what I want and the documentation explicitly mentions this is good for e.g. cleaning up database resources, but I can't find a good example. Code below:
class MyTest : StringSpec() {
lateinit var foo: String
override fun interceptSpec(context: Spec, spec: () -> Unit) {
foo = "foo"
println("before spec - $foo")
spec()
println("after spec - $foo")
}
init {
"some test" {
println("inside test - $foo")
}
}
}
This results in the below output:
before spec - foo
kotlin.UninitializedPropertyAccessException: lateinit property foo has not been initialized
... stack trace omitted ...
after spec - foo