https://kotlinlang.org logo
#mockk
Title
# mockk
s

savrov

11/20/2020, 11:40 PM
Hi, can someone pls explain me the difference between
mockk()
and
any()
. Why when i have smth like
Copy code
coEvery { foo(any()) } returns SomeObject
it works. But when i replace
any()
with
mockk()
, its print out:
Copy code
exception=io.mockk.MockKException: no answer found for: SomeClass(#9).foo$domain(ParamType(#5), continuation {})))
b

bbaldino

11/20/2020, 11:58 PM
AFAIK,
mockk()
is to create a mock, whereas
any()
is a matcher that will match any argument. You'd want to use
any()
in that situation if you want to return some result regardless of what the argument passed to
foo
was.
t

thanksforallthefish

11/23/2020, 8:14 AM
the framework implicitly uses a
eq
matcher when you don’t specify one, so
foo(mockk())
is equivalent to
foo(eq(mockk()))
. as brian said,
mockk()
creates a strict-by-default mock, meaning every method call on the created mock needs to be known. anyway, you want to use
any()
in your case
21 Views