You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mockito.verifyZeroInteractions() actually does not do what it advertises. The purpose of this ticket is to discuss whether to change the behavior of this method in Mockito 3.
Details
Based on user feedback at #977, from @ffissore, "verifyZeroInteractions" API can be misleading. When you read that method in test code, you expect zero interactions with specified mocks. However, "verifyZeroInteractions" is only an alias to "verifyNoMoreInteractions" and in fact, it does not guarantee that there were zero interactions. Let's use examples to illustrate the problem
Feedback needed
Please comment / vote / state your opinion about changing the behavior of "verifyZeroInteractions" so that it actually ensures that there were zero interactions with the mock (regardless if previously verified or not).
Examples
Below examples illustrate current behavior of Mockito 2.x, in case you are puzzled what this ticket is about.
Example 1 - verifyNoMoreInteractions
mock.foo();
verify(mock).foo();
verifyNoMoreInteractions(mock); //pretty clear I think
Example 2 - verifyZeroInteractions
mock.foo();
verify(mock).foo();
verifyZeroInteractions(mock);
//above passes because verifyZeroInteractions == verifyNoMoreInteractions//and we already have verified the only method invoked on the mock
Example 3 - verifyZeroInteractions with regular stubbing
Example 4 - verifyZeroInteractions with new strict stubbing
given(mock.foo()).willReturn("x");
assertEquals("x", mock.foo());
verifyZeroInteractions(mock);
//above passes because with strict stubbing//stubbed method are implicitly verified when they are "used"//this is one of key features of strict stubbing (DRY, don't repeat yourself)
The text was updated successfully, but these errors were encountered:
…elegating to verifyNoMoreInteractions (#995)
* Fixes#989
Introducing verifyNoInteractions, that checks if the number of
invocations on given mock(s) is zero, failing otherwise
* Added missing (?) @test annotation
* Removed try catch block by using isMock
Problem
Mockito.verifyZeroInteractions() actually does not do what it advertises. The purpose of this ticket is to discuss whether to change the behavior of this method in Mockito 3.
Details
Based on user feedback at #977, from @ffissore, "verifyZeroInteractions" API can be misleading. When you read that method in test code, you expect zero interactions with specified mocks. However, "verifyZeroInteractions" is only an alias to "verifyNoMoreInteractions" and in fact, it does not guarantee that there were zero interactions. Let's use examples to illustrate the problem
Feedback needed
Please comment / vote / state your opinion about changing the behavior of "verifyZeroInteractions" so that it actually ensures that there were zero interactions with the mock (regardless if previously verified or not).
Examples
Below examples illustrate current behavior of Mockito 2.x, in case you are puzzled what this ticket is about.
Example 1 - verifyNoMoreInteractions
Example 2 - verifyZeroInteractions
Example 3 - verifyZeroInteractions with regular stubbing
Example 4 - verifyZeroInteractions with new strict stubbing
The text was updated successfully, but these errors were encountered: