Richard Schielek
11/12/2025, 3:30 PMInstancePerLeaf is gone, I found myself restoring a fresh state before each leaf. Wouldn't it be nice to have something similar to the following? Does kotest maybe already have something like this? Or should all before* functions maybe return delegates?
fun <T> ContainerScope.runningBeforeAny(initializer: () -> T): ReadOnlyProperty<Any?, T> {
var value: T? = null
beforeAny {
value = initializer()
}
@Suppress("UNCHECKED_CAST")
return ReadOnlyProperty { _, _ -> value as T }
}
object Spec : FreeSpec({
"Given an empty list of numbers" - {
val numbers by runningBeforeAny { mutableListOf<Int>() }
"when adding one" - {
beforeAny { numbers.add(1) }
"the sum should be one" {
numbers.sum() shouldBe 1
}
"the size should be one" {
numbers shouldHaveSize 1
}
"when adding another one" - {
beforeAny { numbers.add(1) }
"the sum should be two" {
numbers.sum() shouldBe 2
}
"the size should be two" {
numbers shouldHaveSize 2
}
}
}
"when leaving empty" - {
"the sum should be 0" {
numbers.sum() shouldBe 0
}
}
}
})sam
11/13/2025, 6:17 AMRichard Schielek
11/13/2025, 11:21 AMReceived a completed event for test with unknown id '1.18'. Registered test ids: '[1.1, 1.3, 1.2, 1.5, 1.4, :mymodule:test]'
java.lang.IllegalArgumentException: Received a completed event for test with unknown id '1.18'. Registered test ids: '[1.1, 1.3, 1.2, 1.5, 1.4, :mymodule:test]'Richard Schielek
11/14/2025, 12:34 PM