Do you have maybe any data regarding how many peop...
# kotest
b
Do you have maybe any data regarding how many people use
IsolationMode.InstancePerLeaf
?
😭 1
In multiple projects since 2019, i've been using
InstancePerLeaf
, because we've developed methodology to resume Coroutines from mocks in following containers and test different outcomes for different resumed values. Let's assume that there is repository that make some request with api. Tests for it would like this:
Copy code
class RepoTest : CustomSpec({

    val api: Api = mockk()
    val requestContinuation = suspendContinuationFor { api.execute() }
    val sut = Repo(
        api = api,
    )

    "On request" - {
        val result = scope.async { sut.request() }

        "requests api" { coVerify(exactly = 1) { api.execute() } }

        "On success" - {
            requestContinuation.resume(Result.success(Unit))

            "succeeds" { result.await() shouldBe Result.success(Unit) }
        }

        "On failure" - {
            val exception = Exception("Network error")
            requestContinuation.resume(Result.failure<Unit>(exception))

            "fails" { result.await() shouldBe Result.failure<Unit>(exception) }
        }
    }
})
This test is basic, but methodology allowed us to complex cases, where previous steps in scenario were clearly visible. And there is just no way to achieve it with any other
IsolationMode
l
Yes, we also used
InstancePerLeaf
in all our tests and miss it very much. It was useful for testing branching out of test cases, like e.g. different user reactions to the same dialog, different outcomes of a request etc.
r
We also used it extensively. I am very sad to see it go. For me it was the major selling point of kotest. I wish the kotest team would still support it in future versions of kotest (maybe with opt-in annotation?).
l
I think the train is gone on this one. There were many discussions about it. From the 6.0 release notes, there were apparently some edge cases in
InstancePerLeaf
and
InstancePerTest
, which were too hard to resolve.