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

voben

01/23/2020, 4:47 AM
What’s the difference between using
Copy code
every {} returns something
and
Copy code
every {} answers {something}
s

streetsofboston

01/23/2020, 5:23 AM
In the first example,
something
is evaluated only once and immediately. The 2nd example does not evaluate
something
immediately and will evaluate it later, each time when the mocked method is called.
👏 2
v

viralshah

01/23/2020, 5:26 AM
adding onto that, usually you give a lambda supplier to calculate the result to the
answers
clause where as
returns
takes an actual result
i

ivano

01/23/2020, 7:19 AM
I thought
answers
was for the callbacks only
s

s1m0nw1

01/23/2020, 8:38 AM
You can use
answers
to access the passed in parameters to respond with a specialized return value
l

LeoColman

01/23/2020, 1:59 PM
You can also use answers to a more "complex" mock, that do more things
every {} answers { println("Mock!"); something }
471 Views