异常报错信息:

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的更多相关文章

  1. JUnit + Mockito 单元测试(二)(good)

    import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import java.util.Lis ...

  2. Junit mockito 测试Controller层方法有Pageable异常

    1.问题 在使用MockMVC+Mockito模拟Service层返回的时候,当我们在Controller层中参数方法调用有Pageable对象的时候,我们会发现,我们没办法生成一个Pageable的 ...

  3. Junit mockito解耦合测试

    Mock测试是单元测试的重要方法之一. 1.相关网址 官网:http://mockito.org/ 项目源码:https://github.com/mockito/mockito api:http:/ ...

  4. Android 单元测试(junit、mockito、robolectric)

    1.运用JUnit4 进行单元测试 首先在工程的 src 文件夹内创建 test 和 test/java 文件夹. 打开工程的 build.gradle(Module:app)文件,添加JUnit4依 ...

  5. Mockito Hello World

    Mockito Hello World 项目配置 IDE是Intellij IDEA,用gradle配置项目. 新建一个Java项目,gradle中需要有这个:   repositories { jc ...

  6. mockito使用心得

    前提:pom引用<dependency> <groupId>junit</groupId> <artifactId>junit</artifact ...

  7. Mock之easymock, powermock, and mockito

    easymock, powermock, and mockito Easymock Class Mocking Limitations To be coherent with interface mo ...

  8. 用Mockito mock普通的方法

    上面的例子是很理想化的状态,但是在实际的开发中,我们需要经常调用一些依赖特定环境的函数或者调用同事写的代码,而同事仅提供了接口.这个时候就需要利用Mockito来协助我们完成测试. 当然,你可以选择e ...

  9. mock测试框架Mockito

    无论是敏捷开发.持续交付,还是测试驱动开发(TDD)都把单元测试作为实现的基石.随着这些先进的编程开发模式日益深入人心,单元测试如今显得越来越重要了.在敏捷开发.持续交付中要求单元测试一定要快(不能访 ...

随机推荐

  1. Subsets LeetCode总结

    Subsets 题目 Given a set of distinct integers, nums, return all possible subsets. Note: The solution s ...

  2. FindWindow和FindWindowEx

    函数原型:FindWindow(lpszClassName,lpszWindowName) 参数:lpszClassName--窗口类名;lpszWindowName--窗口标题 功能:查找窗口,未找 ...

  3. JavaScript操作DOM(动态表格处理)

    <html> <title>动态处理表格数据</title> <head> <script type="text/javascript& ...

  4. 忘记Oracle系统管理员sys的密码

    sqlplus / as sysdba; alter user sys identified by newpwd***;

  5. chrome --headless --disable-gpu --dump-dom http://www.python.org

    Driving Headless Chrome with Python:Python chrome --headless --disable-gpu --dump-dom http://www.pyt ...

  6. 查找(二)简单清晰的B树、Trie树具体解释

    查找(二) 散列表 散列表是普通数组概念的推广.因为对普通数组能够直接寻址,使得能在O(1)时间内訪问数组中的任何位置.在散列表中,不是直接把keyword作为数组的下标,而是依据keyword计算出 ...

  7. wireshark提取gzip格式的html

    原文地址:http://blog.csdn.net/vah101/article/details/44102501 首先使用wireshark启动抓包,然后以百度为例,访问百度的首页,之后停止抓包,w ...

  8. java 实现好看的图形验证码

    package com.invoice.utils; import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.Aff ...

  9. 算法:堆排序(Heap Sort)

    备注 考虑到 Heap 的特性,很容易想到将其用作排序的用处,为了提高效率需要适当的改进一下,如:in place remove 和 in place move down. 代码 using Syst ...

  10. Round #169 (Div. 2)C. Little Girl and Maximum Sum

    1.用退化的线段树(也就是没有区间查询)做... 2.注意longlong. #include<cstdio> #include<cstring> #include<io ...