异常原因:

1.mockito的jar包中缺少方法

2.mock方法的时候,返回的是对象,而对象没有重写equals方法

3.mock的实例方法调用方法错误

解决方法:

1.用powermock中的api解决问题,在类中添加:@RunWith(PowerMockRunner.class)

2.如果是第二种情况,则需要重写返回对象的equals方法

3.

把A a = new A();

PowerMockito.when(a.getTemplate()).thenReturn(template);

改成:

@Mock
private A a= spy(new A());

PowerMockito.when(a.getTemplate()).thenReturn(template);

org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'的更多相关文章

  1. org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue

    错误原因:mock的时候,不能mock重载的方法 解决方法:直接mock它的父类的方法 org.mockito.exceptions.misusing.CannotStubVoidMethodWith ...

  2. docker: "build" requires 1 argument. See 'docker build --help'.

    http://bbs.csdn.net/topics/391040030 docker build  --tag="ouruser/sinatra:v3" -<Dockerf ...

  3. 基于spring-boot的应用程序的单元+集成测试方案

    目录 概述 概念解析 单元测试和集成测试 Mock和Stub 技术实现 单元测试 测试常规的bean 测试Controller 测试持久层 集成测试 从Controller开始测试 从中间层开始测试 ...

  4. Mockito: InvalidUseOfMatchersException

    异常报错信息: org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument match ...

  5. This exception may occur if matchers are combined with raw values

    org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!3 ma ...

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

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

  7. Mockito常用方法及示例

    Mockit是一个开源mock框架,官网:http://mockito.org/,源码:https://github.com/mockito/mockito 要使用Mockit,首先需要在我们工程中引 ...

  8. Powermockito 针对方法中new 对象的模拟,以及属性中new 对象的模拟

    PowerMocker 是一个功能逆天的mock 工具. 一,Powermockito 针对方法中new 对象的模拟 // 如何才能mock掉 WeChatConfigUtil 这个类,让 weCha ...

  9. Mockito文档-单元测试技术

    Overview  Package   Class  Use  Tree  Deprecated  Index  Help     PREV CLASS   NEXT CLASS FRAMES     ...

随机推荐

  1. ZOJ 3937 More Health Points (2016 浙江省赛 B题,可持久维护凸壳)

    题目链接  2016 ZJCPC Problem B 题意  CF 660F的树上版本. 其他做的方法都差不多,关键是把凸壳放到树上. 每次确定扔掉几个元素的时候直接$O(1)$修改(先不清楚这个位置 ...

  2. Extjs Ext.grid.column.Column 隐藏显示列

    1.根据字段名字 grid.down("gridcolumn[dataIndex=PLAN_QTY]").show();//hide() 2.根据列号 grid.columns[1 ...

  3. 彻底理解Java中的hashcode方法(转)

    本文转自http://www.importnew.com/18851.html 哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有 ...

  4. python多线程,守护线程

    https://www.cnblogs.com/liuyang1987/p/6292321.html

  5. object references an unsaved transient instance - save the transient instance before flushing异常问题处理

    一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...

  6. 解决svn锁定

    问题:今天去公司 svn-update的时候,报错svn:E155004,提示说什么locked 解决:svn cleanup解除锁定,然后就可以操作了. 原因:SVN 本地更新时,由于一些操作中断更 ...

  7. thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (-4) SASL(-4): no mechanism available: No worthy mechs found

    thrift.transport.TTransport.TTransportException: Could not start SASL: Error in sasl_client_start (- ...

  8. 速查笔记(Linux Shell编程<上>)

    转载自: http://www.cnblogs.com/stephen-liu74/archive/2011/11/01/2202027.html 零.shell中的内部变量: 1.    $?:   ...

  9. ECShop后台管理菜单修改

    ECShop中,和后台菜单相关的文件有两个: ·菜单项:admin\includes\inc_menu.php·菜单文本:languages\zh_cn\admin\common.php 所以,要修改 ...

  10. 2017.3.31 spring mvc教程(二)核心流程及配置详解

    学习的博客:http://elf8848.iteye.com/blog/875830/ 我项目中所用的版本:4.2.0.博客的时间比较早,11年的,学习的是Spring3 MVC.不知道版本上有没有变 ...