Hi, can someone pls explain me the difference betw...
# mockk
s
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
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
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