Hello everyone, What do I return when I don't care...
# mockk
m
Hello everyone, What do I return when I don't care about the return value? I can't return unit since the return type is
SomeClass
. Do I have to
return SomeClass()
or is there something else available like return any or return whatever?
m
off the top of my head i’d say you can use a relaxed mock. Can you please provide a full example of your problem though?
m
I'm testing a function with this line
Copy code
batteryImage.setImageDrawable(context.getResources().getDrawable(R.drawable.battery_100));
I'm mocking
getDrawable
, I don't care what it returns I just want to verify it was called with R.drawable.battery_100. And I do not want to execute the getresources and getdrawable. I know it's not ideal code to unit test but it's what I have right now. Fixing these thingsi s on the planning for later. Thanks for your reply!
c
you can either use
justRun
or use a relaxed mock.
m
@christophsturm ah yes instead of
every
? Sorry I forgot about that one, I was trying
just Runs
as return value. Thanks!
👍 1
c
I think just run as return value should also work
m
just
only works on Unit
m
yep that’s right
just runs
can only be used on methods returning Unit. i’d say your best option is to use a relaxed mock
m
I'm happy with the justRun, I will consider relaxed mock when I have more cases like this. Thanks!
👍 1