Unit testing 方法抛出';org.mockito.exceptions.misusing.invalidUseofMatcherException';例外。

Unit testing 方法抛出';org.mockito.exceptions.misusing.invalidUseofMatcherException';例外。,unit-testing,testing,junit,Unit Testing,Testing,Junit,我正在尝试测试此方法,但出现以下错误: Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception. 在这一行 代码: 我想说的是,您不应该使用boolean.class,因为小写布尔值是一个原语,并且不会返回java.lang对象。 使用Boolean.class或anyBoolean()对于您正在使用的大多数类型,已经有内置的匹配器 when(tester.method(an

我正在尝试测试此方法,但出现以下错误:

Method threw 'org.mockito.exceptions.misusing.InvalidUseOfMatchersException' exception. 
在这一行 代码:


我想说的是,您不应该使用
boolean.class
,因为小写布尔值是一个原语,并且不会返回java.lang对象。
使用
Boolean.class
anyBoolean()

对于您正在使用的大多数类型,已经有内置的匹配器

when(tester.method(anyString(), any(LocalDate.class), anyBoolean(),anyBoolean(), anyString()))
.thenReturn(item);
参考文献

对于基本类型,请使用
any{Type}()
family


你能发布更多的测试代码吗?特别是围绕testerSince Mockito 2.1.0的模拟,anyChar()只对字符有效primitives@dementis我直接从文件中引用了这句话。我能理解这种混乱。更新。
when(tester.method(anyString(), any(LocalDate.class), anyBoolean(),anyBoolean(), anyString()))
.thenReturn(item);