I need to verify that a method has been called on an object. So I make a spy of this object:
obj = spyk(obj)
And then I verify that a method has been called:
verify(exactly = 1) { obj.f(3) }
The test fails with the following error message:
java.lang.AssertionError: Verification failed: call 1 of 1: obj(#2).f(eq(3))) was not called.
However I can clearly see the method f
being called:
- I can break in that method in debug mode
- I print out
hello world from f()
in that method and see it being printed.
How do I use spies correctly in mockk?
P.S.
I tried doing val obj = spyk(obj())
but I get lateinit has not been initialized error
because I need to set a parameter in obj
as so:
obj.setDependency(friend)
But in the case where I first do val obj = spyk(obj())
and then call obj.setDependency(friend)
like I explained above I end up with a lateinit has not been initialized error
Can someone please help me resolve this issue?