mockito验证参数
Mockito Verify methods are used to check that certain behavior happened. We can use Mockito verify methods at the end of the testing method code to make sure that specified methods are called.
Mockito Verify方法用于检查某些行为是否发生。 我们可以在测试方法代码的末尾使用Mockito验证方法,以确保调用了指定的方法。
Mockito验证 (Mockito Verify)
- Mockito verify() method can be used to test number of method invocations too. We can test exact number of times, at least once, at least, at most number of invocation times for a mocked method. Mockito verify()方法也可以用于测试方法调用的数量。 我们可以测试模拟方法的确切次数,至少一次,至少最多一次。
- We can use
verifyNoMoreInteractions()
after all the verify() method calls to make sure everything is verified. If any method verification is still left, it will fail and provide proper message. 在所有verify()方法调用之后,我们可以使用verifyNoMoreInteractions()
来确保所有内容verifyNoMoreInteractions()
通过验证。 如果仍然有任何方法验证,它将失败并提供正确的消息。 verifyZeroInteractions()
behavior is same asverifyNoMoreInteractions()
method.verifyZeroInteractions()
行为与verifyNoMoreInteractions()
方法相同。- We can use
inOrder()
method to verify the order of method invocation. We can skip a method invocation but the methods being verified must be in the same order. 我们可以使用inOrder()
方法来验证方法调用的顺序。 我们可以跳过方法调用,但是要验证的方法必须具有相同的顺序。
Let’s look at some of the mockito verify method examples.
让我们看一些模