Kev*_*vyp 9 java testing matcher mockito
我想做这个:
verify(function, Mockito.times(1)).doSomething(argument1, Matchers.any(Argument2.class));
Run Code Online (Sandbox Code Playgroud)
当自变量1的类型的specfic实例参数1和参数2是该类型的任何实例ARGUMENT2.
但是我收到一个错误:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers! 2 matchers expected, 1 recorded. This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String"); When using matchers, all arguments have to be provided by matchers. For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
Run Code Online (Sandbox Code Playgroud)
按照这个建议我可以写下面的内容,一切都很好:
verify(function, Mockito.times(1)).doSomething(Matchers.any(Argument1.class), Matchers.any(Argument2.class));
Run Code Online (Sandbox Code Playgroud)
我正在寻找Argument1类型的任何争论和Argument2类型的任何参数.
我怎样才能实现这种理想的行为?
fge*_*fge 16
有一个以上可能的参数匹配器,一个是eq异常消息中提到的.使用:
verify(function, times(1)).doSomething(eq(arg1), any(Argument2.class));
Run Code Online (Sandbox Code Playgroud)
(静态进口应该在那里 - eq()是Matchers.eq()).
你也有same()(它确实引用相等,即==),更一般地说,你可以编写自己的匹配器.
| 归档时间: |
|
| 查看次数: |
5534 次 |
| 最近记录: |