org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
4 matchers expected, 3 recorded:
-> at com.yihaodian.wap.service.AddressServiceTest.testInsertGoodReceiverByTokenV2(AddressServiceTest.java:136)
-> at com.yihaodian.wap.service.AddressServiceTest.testInsertGoodReceiverByTokenV2(AddressServiceTest.java:136)
-> at com.yihaodian.wap.service.AddressServiceTest.testInsertGoodReceiverByTokenV2(AddressServiceTest.java:136)
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"));
For more info see javadoc for Matchers class.
报错的测试代码:
Mockito.
when
(baseDaoRead.queryForObject(Mockito.
anyString
(), Mockito.
anyMap
(), String.
class
)).thenReturn("123.11");
改正确之后的测试代码:(主要是
String.class
不是使用
Matchers
传参)
Mockito.
when
(baseDaoRead.queryForObject("industry.getMaxYestPayIdx", params, String.
class
)).thenReturn("123.11");
或者这样也是正确的:
Mockito.
when
(baseDao.queryForList(Mockito.
anyString
(), Mockito.
anyMap
())).thenReturn(list3);
主要差异是对传入的字符串做了
Matchers.eq()
动作
原因:
使用
Matchers
不能只针对部分参数,所有参数都应该采用
Matchers