異常報錯信息:java
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.
報錯的測試代碼:ide
Mockito.when(baseDaoRead.queryForObject(Mockito.anyString(), Mockito.anyMap(), String.class)).thenReturn("123.11");測試
改正確以後的測試代碼:(主要是String.class不是使用Matchers傳參)spa
Mockito.when(baseDaoRead.queryForObject("industry.getMaxYestPayIdx", params, String.class)).thenReturn("123.11");code
或者這樣也是正確的:blog
Mockito.when(baseDao.queryForList(Mockito.anyString(), Mockito.anyMap())).thenReturn(list3);字符串
主要差別是對傳入的字符串作了Matchers.eq()動做 get
緣由:使用Matchers不能只針對部分參數,全部參數都應該採用Matchersit