Mockk: equivalent of verifyNoMoreInteractions() ?

Created on 21 Mar 2018  路  10Comments  路  Source: mockk/mockk

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 ;) ?

help wanted

Most helpful comment

May be

verify { listOf(mock1, mock2) wasNot Called }

is what you are searching for

All 10 comments

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/

Was this page helpful?
0 / 5 - 0 ratings