← Back to list

Don’t Forget an Answer If Mocking a Function w/ mockk; Watch for “No answer provided” vs "... found"

Brian Terczynski · 2026-03-31 05:47 · 0 claps · 0.8 min read
#mockk #kotlin #unit-testing
Open on Medium ↗
Wiki topics: 📱 · Mobile Development

Don’t Forget an Answer If You Are Mocking a Function With mockk; Watch for “No answer provided” Versus “No answer found”

A dumb mistake I made recently.

I was using mockk in a unit test. And I was getting the following error:

io.mockk.MockKException: No answer found for MyClass(#123).myFunction(argument1, argument2) among the configured answers ...

So I added the answer for it:

coEvery {
    myObject.myFunction(
        argument1,
        argument2,
    )
}

And it was still happening:

io.mockk.MockKException: No answer providedfor MyClass(#123).myFunction(argument1, argument2)

And I was confused. I set all of the parameters to be exactly equal. I was calling coEvery before this (suspend) function was called. Why was it still not working?

Well, I didn’t look closely enough at the actual exception. It was saying something different: no answer provided instead of no answer found.

And then I realized something: I didn’t add a returns or answers after the coEvery. Oops! I mean, it compiled. It just wasn’t complete.

Once I added a returns, then the test worked.

coEvery {
    myObject.myFunction(
        argument1,
        argument2,
    )
} returns MyResult(12345)

Anyways, just a dumb mistake I made, but perhaps something that can be easily missed since “No answer found” sounds awfully similar to “No answer provided”.

Just something to watch out for.


메타데이터
post_id
38adc2d1d66e
slug
dont-forget-an-answer-if-mocking-a-function-w-mockk-watch-for-no-answer-provided-vs-found-38adc2d1d66e
url
https://medium.com/@bterczynski/dont-forget-an-answer-if-mocking-a-function-w-mockk-watch-for-no-answer-provided-vs-found-38adc2d1d66e
canonical_url
https://medium.com/@bterczynski/dont-forget-an-answer-if-mocking-a-function-w-mockk-watch-for-no-answer-provided-vs-found-38adc2d1d66e
author_url
https://medium.com/@bterczynski
status
ok
fetched_at
2026-06-26 06:47:43