Klitos Kyriacou
06/11/2025, 3:44 PMval result: MyResultType
mockkObject(SomeObject) {
every { SomeObject.foo() } returns "bar"
result = callUnitUnderTest()
}
result.a shouldBe 1
result.b shouldBe 2
The idea was to keep the time the object is mocked to a minimum. The object doesn't have to remain mocked while I'm doing the assertions.
Unfortunately, the Kotlin compiler gives an error saying result
is reassigned inside the lambda and uninitialized outside the lambda. This is because it doesn't know that the lambda is guaranteed to be called exactly once. This can be fixed by the use of contracts. Is there any chance it can be done in a future release?Alex Kuznetsov
06/11/2025, 5:27 PMKlitos Kyriacou
06/12/2025, 8:08 AM