0
ユニットテストで標準beforeAll
/afterAll
タイプのセットアップを実行しようとしていますが、いくつか問題があります。 interceptSpec
の機能が私の望むものだと思われており、ドキュメントに明示的に言及されています。データベースのリソースをクリーンアップするが、私は良い例を見つけることができません。以下のコード:kotlintest 2.x(interceptSpec)で共有リソースを正しく初期化する方法
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")
}
}
}
これについては、以下の出力が生成されます。
before spec - foo
kotlin.UninitializedPropertyAccessException: lateinit property foo has not been initialized
... stack trace omitted ...
after spec - foo