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

Robert MacLean

05/27/2021, 8:41 AM
Hi, Is there a difference between
mockk<T>(relaxed = true)
vs.
spyk
? I tend to think of them as the same and use the former is useful for when there is a default constructor and the the latter if I need to pass properties to a constructor, and otherwise think they end up the same…. but maybe I am wrong?
m

Mattia Tommasone

05/27/2021, 8:44 AM
yes there is a slight difference: when you invoke a method on a spy, if it has not been stubbed, the actual method on the object will be invoked. if you do the same thing on a relaxed mock, the actual method will not be invoked and it will return a default answer, e.g. an empty list if the method returns a List
t

thanksforallthefish

05/27/2021, 8:44 AM
usually you use mocks to configure a behavior, spies to observe
👍 1
mattia ninjad me 😄
🥷 1
r

Robert MacLean

05/27/2021, 10:33 AM
ah, that is a very subtle and interesting difference thanks @Mattia Tommasone
m

Mattia Tommasone

05/27/2021, 4:20 PM
@thanksforallthefish’s point is definitely valid though
3 Views