Mockito: InvalidUseOfMatchersException
异常报错信息:
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
Mockito: InvalidUseOfMatchersException的更多相关文章
- JUnit + Mockito 单元测试(二)(good)
import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import java.util.Lis ...
- Junit mockito 测试Controller层方法有Pageable异常
1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...
- Junit mockito解耦合测试
Mock测试是单元测试的重要方法之一. 1.相关网址 官网:http://mockito.org/ 项目源码:https://github.com/mockito/mockito api:http:/ ...
- Android 单元测试(junit、mockito、robolectric)
1.运用JUnit4 进行单元测试 首先在工程的 src 文件夹内创建 test 和 test/java 文件夹. 打开工程的 build.gradle(Module:app)文件,添加JUnit4依 ...
- Mockito Hello World
Mockito Hello World 项目配置 IDE是Intellij IDEA,用gradle配置项目. 新建一个Java项目,gradle中需要有这个: repositories { jc ...
- mockito使用心得
前提:pom引用<dependency> <groupId>junit</groupId> <artifactId>junit</artifact ...
- Mock之easymock, powermock, and mockito
easymock, powermock, and mockito Easymock Class Mocking Limitations To be coherent with interface mo ...
- 用Mockito mock普通的方法
上面的例子是很理想化的状态,但是在实际的开发中,我们需要经常调用一些依赖特定环境的函数或者调用同事写的代码,而同事仅提供了接口.这个时候就需要利用Mockito来协助我们完成测试. 当然,你可以选择e ...
- mock测试框架Mockito
无论是敏捷开发.持续交付,还是测试驱动开发(TDD)都把单元测试作为实现的基石.随着这些先进的编程开发模式日益深入人心,单元测试如今显得越来越重要了.在敏捷开发.持续交付中要求单元测试一定要快(不能访 ...
随机推荐
- 模板 快速询问GCD
快速询问两个数的GCD 我觉得只有智障会卡这个玩意儿-- const int maxn = 1e6; const int Sqrt_N = 1e3; int pre[maxn + 1] , decom ...
- HDU 5692 Snacks bfs版本dfs序 线段树
Snacks 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5692 Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连 ...
- Oracle DBA学习篇之SQL_TRACE
SQL_TRACE ; ; set serveroutput on; alter session set sql_trace=true; select count(*) from firefox; a ...
- The YubiKey NEO -- Smartcard features
Smartcard features on the YubiKey NEO YubiKeys are a line of small and low-cost hardware security to ...
- Send a WhatsApp Message programatically -- Tasker WhatsTasker
Here is My code snippet: Uri mUri = Uri.parse("smsto:+9876543210"); Intent mIntent = new I ...
- redhat 6.6 安装 (LVM)
http://www.cnblogs.com/kerrycode/p/4341960.html
- Bootstrap 3之美02-Grid简介和应用
本篇主要包括: ■ Grid简介■ 应用Grid■ Multiple Grids Grid简介 Bootstrap中,把页面分成12等份,这就是所谓的Grid. 在Bootstrap中,用类名控 ...
- KJBitmap与KJHttp的深度用法
摘要 本文原创,转载请注明地址:http://kymjs.com/code/2015/09/24/01这篇文章是对KJFrameForAndroid使用的一个深入学习 之前写过一些有关KJFrame的 ...
- mr
大数据技术 —— MapReduce 简介 本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 1.概要很多计算在概念上很直观,但由于输入数据很大, ...
- 什么是软件project?
Normal 0 7.8 pt 0 2 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNo ...