Created
March 16, 2019 16:44
-
-
Save robfletcher/7c67b728e1c657f1b03ca6303b0f67af to your computer and use it in GitHub Desktop.
Demonstration of error verifying calls to a lambda that returns `Unit`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.mockk.mockk | |
import io.mockk.verify | |
import org.junit.jupiter.api.Test | |
class MockkUnitLambdaTest { | |
@Test | |
fun mockUnitLambda() { | |
val fn: (String) -> Unit = mockk(relaxUnitFun = true) | |
fn("foo") | |
verify { fn("foo") } | |
} | |
@Test | |
fun mockUnitLambdaInvoke() { | |
val fn: (String) -> Unit = mockk(relaxUnitFun = true) | |
fn.invoke("foo") | |
verify { fn.invoke("foo") } | |
} | |
@Test | |
fun mockUnitLambdaRelaxed() { | |
val fn: (String) -> Unit = mockk(relaxed = true) | |
fn("foo") | |
verify { fn("foo") } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first 2 tests fail with
io.mockk.MockKException: no answer found for: Function1(#1).invoke(foo)
. The final test passes because it usesrelaxed = true
.