Hi all, I'm converting many tests in Kotlin + Mockk and I wonder how to run the equivalent of verifyNoMoreInteractions() from Mockito?
I can do verifyZeroInteractions() with verify(exactly=0) { .. } but for the other one I don't see a way.
Any help ;) ?
Hi. Let me check
May be
verify { listOf(mock1, mock2) wasNot Called }
is what you are searching for
Dont need to be list, just one mock can be as well
One point to add to this is that verifyZeroInteractions should count for all other interactions
So
val mocked = mock()
every { mocked.x } returns y
//Something happens
verify(exactly = 3) { mocked.x }
//Other methods are called, and I want to make sure mocked.x wasn't called anymore
verify(exactly = 0) { mocked.x }
At least this is mockito's behaviour, not sure if this is expected from Mockk, just commented for clarification
Hi @oleksiyp , just tried this:
every { mock.method(any()) } returns res
...
verify { mock.method(any) }
verify { mock.method wasNot Called }
the second verify makes the test fail.
My workaround is to force the verification with the hit time specified:
verify(exactly =1 ) { mock.method(any) }
but in this way subsequent refactorying of the called code I could change the invokations to 2 instead of 1 and this would break the test.
Correct usage is:
verify { mock wasNot Called }
yes sorry i was doing the correct one already, it was just a typo in this comment.
I guess that verify { mock wasNot Called } is actually the equivalent of Mockito.verifyZeroInteracitons()
Kind of. It is only chrcking for specified mocks, but doing more than that looks not very right thing
Looks like resolved
Update: In case anyone tries to use verify { mock wasNot Called } to replace verifyZeroInteractions() but couldn't pass the test. The correct usage is confirmVerified(mock). See "Verification confirmation" section in https://mockk.io/
Most helpful comment
May be
is what you are searching for