Ben Liblit
06/18/2026, 5:00 PMtestFixture...asParameterForEach scope. One of my tests needs that fixture and also a second test-level fixture. Can I nest testFixture...asParameterForEach scopes? Or is that unwise?
I see this example of nested fixtures. But it's not clear to me the inner test ("test2") would be able to name and access the outer test fixture.Oliver.O
06/18/2026, 9:01 PMobject expression).
With nested fixtures, a test would always receive the innermost one.
Suite-level fixtures provide more flexibility if their invoke operator is used. Such suite-level fixture can be combined across multiple test suite levels.
Is it just one test requiring a second fixture? If so, wouldn't a local property inside the test work?Ben Liblit
06/18/2026, 9:58 PMAutoCloseable, so a standard Kotlin MyFixture().use { myFixture -> ... } works perfectly in my test's body.Oliver.O
06/18/2026, 10:00 PMBen Liblit
06/19/2026, 7:46 PMOliver.O
06/19/2026, 7:52 PMJosh Brown
07/09/2026, 2:15 AMOliver.O
07/09/2026, 11:32 AMval adminEmail by prepared { "my-account-${random.nextInt()}@mail.com" }
test("First test") {
adminEmail() shouldEndWith "@mail.com"
// Within a test, all calls are guaranteed to return the exact same value.
adminEmail() shouldBe adminEmail()
}
test("Second test") {
// This test will receive its own value
// that is shared with no other test.
adminEmail() shouldEndWith "@mail.com"
}
That mechanism would provide more flexibility than TestBalloon's own test-level fixtures. So why wasn't this implemented in TestBalloon itself?
The answer is comprehensibility, which is one of TestBalloon's major design goals.
TestBalloon's fixtures return predictable values within their scope (for test-level fixtures it's the test, for suite-level fixture it's the suite). Their syntactical elements (parameters, receivers) make that clear in plain Kotlin. There is no magic involved.
With Prepared, the above adminEmail() function keeps or changes its result depending on where it is invoked (first time in a test, subsequently in the same test). There is no syntactical element binding the prepared value to a scope. It is magic which has to be learned.
That said: Maybe we can find a way to combine the best of both worlds. And as always with every new feature: For a good start we need concrete real-world use cases, which would be too cumbersome to handle now. Once we have that, we can explore the boundaries of existing solutions and can better judge the upsides and downsides of possible future solutions. Suggestions welcome!