简体   繁体   English

Mockito-完全验证所有参数

[英]Mockito - Verify all arguments exactly

How can I verify multiple calls to a method with different parameters, and also verify that no other parameters were given? 如何验证对具有不同参数的方法的多次调用,又如何验证没有给出其他参数?

I know I can test for multiple arguments like this: 我知道我可以测试多个参数,例如:

@Spy
SomeClass someClass

@Test
public void test() {
  someClass.triggerSomething();

  verify(someClass, times(1)).someMethod(1, 1);
  verify(someClass, times(1)).someMethod(2, 2);
  verify(someClass, times(1)).someMethod(3, 3);
  verify(someClass, times(1)).someMethod(4, 4);
  verify(someClass, times(1)).someMethod(5, 5);
}

How do I verify that I haven't called it with any other combination of parameters? 如何验证是否没有使用其他任何参数组合调用它?

Use verifyNoMoreInteractions(someClass) . 使用verifyNoMoreInteractions(someClass)

Checks if any of given mocks has any unverified interaction. 检查给定的模拟是否有未验证的交互。

You can use this method after you verified your mocks - to make sure that nothing else was invoked on your mocks. 在验证了模拟之后,可以使用此方法-确保在模拟上没有其他任何调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM