Astronaut4449
07/16/2026, 7:56 AMnumbersTest
└── Given an empty list of numbers
├── when adding one
│ ├── the sum should be one
│ ├── the size should be one
│ └── when adding another one
│ ├── the sum should be two
│ └── the size should be two
└── when leaving empty
└── the sum should be 0
Once I define the my list of numbers with
val numbers = testFixture { mutableListOf<Int>() } closeWith { clear() }
There is no way to to obtain and modify it in a nested testsuite.
I found this ugly workaround:
testSuite("Given an empty list of numbers") {
val numbers = testFixture { mutableListOf<Int>() } closeWith { clear() }
testSuite("when adding one") {
val numbers = testFixture { numbers().also { it.add(1) } }
Any suggestion or recommendation?Oliver.O
07/16/2026, 10:21 AMcloseWith() isn't necessary as it will only happen if the list goes out of scope.
I have another solution:
package com.example
import de.infix.testBalloon.framework.core.Test
import de.infix.testBalloon.framework.core.TestFixture
import de.infix.testBalloon.framework.core.TestSuiteScope
import de.infix.testBalloon.framework.core.testSuite
import kotlin.test.assertEquals
val NumbersTest by testSuite {
testSuite("Given an empty list of numbers") {
mutableNumbersSuite("when adding one") {
test("the sum should be one") { numbers ->
numbers.add(1)
assertEquals(1, numbers.sum())
}
test("the size should be one") { numbers ->
assertEquals(1, numbers.size)
}
testSuite("when adding another one") {
test("the sum should be two") { numbers ->
numbers.add(1)
assertEquals(2, numbers.sum())
}
test("the size should be two") { numbers ->
assertEquals(2, numbers.size)
}
}
}
mutableNumbersSuite("when leaving empty") {
test("the sum should be 0") { numbers ->
assertEquals(0, numbers.sum())
}
}
}
}
private fun TestSuiteScope.mutableNumbersSuite(
name: String,
content: TestFixture.Scope<suspend Test.ExecutionScope.(value: MutableList<Int>) -> Unit>.() -> Unit
) = testSuite(name) {
testFixture {
mutableListOf<Int>()
} asParameterForAll {
content()
}
}
You could experiment more along these lines, e.g. I've contemplated providing an additional lambda parameter to mutableNumbersSuite for the initial mutation, but you're also mutating state further down ("when adding another one"), which would not be covered.
Maybe you have even better ideas. In this case, I'd like to hear about them.
Where this isn't practical, you can of course always keep your Kotest tests and just use TestBalloon where it is a better fit.Oliver.O
07/18/2026, 4:38 PMBernd Prünster
07/18/2026, 5:19 PMval numberTest by testSuite(testConfig = TestConfig.singleThreaded()) {
withFixtureGenerator { mutableListOf<Int>() } - {
testSuite("Given an empty list of numbers") { numbers ->
testSuite("when adding one") {
numbers += 1
test("the sum should be one") {
numbers.sum() shouldBe 1
}
test("the size should be one") {
numbers shouldHaveSize 1
}
//copy the numbers list from the outer "when adding one" suite" into a fresh fixture for nesting
withFixtureGenerator { numbers.toMutableList() } - {
testSuite("when adding another one") { numbers ->
numbers += 1
test("the sum should be two") {
numbers.sum() shouldBe 2
}
test("the size should be two") {
numbers shouldHaveSize 2
}
}
}
}
//fresh fixture: numbers is just mutableListOf<Int>() from the very top
testSuite("when leaving empty") { numbers ->
test("the sum should be 0") {
numbers.sum() shouldBe 0
}
}
}
}
}
BUT: I've just discovered a bug in our Addons' fixture generator and the new versions with the fix won't hit maven Central until MondayBernd Prünster
07/20/2026, 6:45 AM