org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'
异常原因:
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'的更多相关文章
- org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue
错误原因:mock的时候,不能mock重载的方法 解决方法:直接mock它的父类的方法 org.mockito.exceptions.misusing.CannotStubVoidMethodWith ...
- docker: "build" requires 1 argument. See 'docker build --help'.
http://bbs.csdn.net/topics/391040030 docker build --tag="ouruser/sinatra:v3" -<Dockerf ...
- 基于spring-boot的应用程序的单元+集成测试方案
目录 概述 概念解析 单元测试和集成测试 Mock和Stub 技术实现 单元测试 测试常规的bean 测试Controller 测试持久层 集成测试 从Controller开始测试 从中间层开始测试 ...
- Mockito: InvalidUseOfMatchersException
异常报错信息: org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument match ...
- This exception may occur if matchers are combined with raw values
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!3 ma ...
- JUnit + Mockito 单元测试(二)(good)
import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; import java.util.Lis ...
- Mockito常用方法及示例
Mockit是一个开源mock框架,官网:http://mockito.org/,源码:https://github.com/mockito/mockito 要使用Mockit,首先需要在我们工程中引 ...
- Powermockito 针对方法中new 对象的模拟,以及属性中new 对象的模拟
PowerMocker 是一个功能逆天的mock 工具. 一,Powermockito 针对方法中new 对象的模拟 // 如何才能mock掉 WeChatConfigUtil 这个类,让 weCha ...
- Mockito文档-单元测试技术
Overview Package Class Use Tree Deprecated Index Help PREV CLASS NEXT CLASS FRAMES ...
随机推荐
- POJ 3080-Blue Jeans【kmp,字符串剪接】
Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20695 Accepted: 9167 Descr ...
- Android Studio+WebApi(一)属于我们自己的App
AndroidStudio(以后都简称AS),作为google的亲儿子,终于出了个像样的android ide,再也不用在eclipse中又是Adt,又是这又是那的,一大堆的集成了.废话不多说,这个系 ...
- sql 分组后按时间降序排列再取出每组的第一条记录
原文:sql 分组后按时间降序排列再取出每组的第一条记录 竞价记录表: Aid 为竞拍车辆ID,uid为参与竞价人员ID,BidTime为参与竞拍时间 查询出表中某人参与的所有车辆的最新的一条的竞价记 ...
- Eclipse常用小知识汇总
原文:http://blog.csdn.net/jinzhencs/article/details/50462370 1.修改注释 自动出来的author
- 【微信】2.微信小程序开发--官方开发工具使用说明
承接第一篇 =============================================== 关于微信小程序开发使用IDE,曾经自己动摇过. 到底是采用 微信官方小程序开发工具 WebS ...
- ServicePointManager.ServerCertificateValidationCallback 冲突的解决
ServicePointManager是用于创建. 维护和删除的实例的静态类ServicePoint类. 当应用程序请求对 Internet 资源统一资源标识符 (URI) 的连接通过ServiceP ...
- XP右键菜单添加“打开所在文件夹”功能
把以下文字保存为add.reg文件,双击后确定就可以了. REGEDIT4 [HKEY_CLASSES_ROOT\*\Shell\打开所在文件夹(&O)] [HKEY_CLASSES_ROOT ...
- Hadoop之Hive详解
1.什么是Hive hive是基于hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表 并提供类sql查询功能 2.为什么要用Hive 1.直接使用hadoop所面临的问题 人员学 ...
- How does a single thread handle asynchronous code in JavaScript?
原文:https://www.quora.com/How-does-a-single-thread-handle-asynchronous-code-in-JavaScript ----------- ...
- 转:Spring mvc中@RequestMapping 6个基本用法小结
Spring mvc中@RequestMapping 6个基本用法小结 发表于3年前(2013-02-17 19:58) 阅读(11698) | 评论(1) 13人收藏此文章, 我要收藏 赞3 4 ...