mockito-kotlin
mockito-kotlin copied to clipboard
Improvement: Don't check whenever(mock)-calls on verifyNoMoreInteractions(mock)
@Test
internal fun `some testing`() {
val pong = Pong()
whenever(mock.ping()).thenReturn(pong)
assertThat(pingService.sendPing()).isEqualTo(pong)
// this verification is already defined by whenever(...)
verify(mock).ping()
// but is is needed, because otherwise this will fail
verifyNoMoreInteractions(mock)
}
It will be reduce code if verifyNoMoreInteractions
will not check whenever
-calls or this could be configurable by an optional parameter.
// this verification is already defined by whenever(...) verify(mock).ping()
verify(...)
checks that mock.ping()
is invoked. Whenever(...)
verifies nothing, but just defines what should happen if mock.ping()
is invoked. And this depends on the implementation of pingService.sendPing()
.
Yes you are right. But a verifyNoMoreInteractionsAndVerifyWhenever
could help.
My tests often look like the one described above. And (for me) it feels like duplicating code.
Would Mockito's Strictness API help here?