First I want to thank you for this amazing library, as far as I know it's the only mock framework made purely with Kotlin.
Now the bad news :D
If an Object has one of its methods annotated with @JvmStatic, when trying to mock that method, an exception is thrown.
object ObjectAnnotated {
@JvmStatic fun foo() = "foo"
}
class ObjectAnnotatedTest {
@Test
fun verifyFoo() {
objectMockk(ObjectAnnotated).mock()
every { ObjectAnnotated.foo() } returns "bar"
assert(ObjectAnnotated.foo() == "bar")
}
}
io.mockk.MockKException: Missing calls inside every { ... } block.
at io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14)
at io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8)
at io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:42)
at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:48)
at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
at com.mufumbo.android.recipe.search.provider_login.ObjectAnnotatedTest.verifyFoo(ObjectAnnotatedTest.kt:25)
I'm using latest version -> 1.8
Please let me know if you need further support.
Just try static mock on that object class
I don't know what you mean by static mock. Can you share the implementation based on my previous example?
Can't check right now this code(hope it works):
class ObjectAnnotatedTest {
@Test
fun verifyFoo() {
staticMockk<ObjectAnnotated>().use {
every { ObjectAnnotated.foo() } returns "bar"
assert(ObjectAnnotated.foo() == "bar")
}
}
}
It works, thanks @oleksiyp for the support 馃憤
Most helpful comment
It works, thanks @oleksiyp for the support 馃憤