I have an Android Studio project that hadn't been updated for a while. I upgraded from gradle 4.x to 8.x and from Kotlin 1.4 to 1.8. After doing so, the following test fails and I can't figure out why. Other tests are passing.
In the test below, cb is a callback that is called if there is an error loading the data.
it("test desc") {
val cb: ((CustomError?) -> Unit) = mockk()
every { cb.invoke(any()) } just Runs
myClass.loadData(MyOptions.Init(), null, cb)
verifyOrder {
harness.miController.sendEvent(BaseEvent.LOAD_DATA, any(), any())
if (resolve) {
cb.invoke(any()) wasNot Called
} else {
cb.invoke(CustomError.LOAD_DATA)
}
}
}
I'm using:
When I step through the tests, when resolve is true cb.invoke is not being called and when resolve is false, cb.invoke is called with the error. So it looks like it should pass, but it gets reported as failing.
The library itself is functioning correctly, so it appears to be a problem with the test.
Any ideas why it fails and how to fix?
wasNot
is not intended to be used like this, it is to check whether object (mock, spy) as a whole have any registered calls
that means when you write
cb.invoke(any()) wasNot Called
you are actually checking if object returned by invoke has been called
If you do not have any other calls to cb
you can simply change to cb wasNot Called