异常原因:

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. Python与数据结构[1] -> 栈/Stack[0] -> 链表栈与数组栈的 Python 实现

    栈 / Stack 目录 链表栈 数组栈 栈是一种基本的线性数据结构(先入后出FILO),在 C 语言中有链表和数组两种实现方式,下面用 Python 对这两种栈进行实现. 1 链表栈 链表栈是以单链 ...

  2. POJ 3368 Frequent values(线段树区间合并)

    [题目链接] http://poj.org/problem?id=3368 [题目大意] 有一个有序序列,要求区间查询出现次数最多的数 [题解] 维护每个区间左端点和右端点,以及左右的长度,还有区间的 ...

  3. source insight研究——快捷键篇

    转:http://blog.csdn.net/ison81/article/details/3510426 关于键盘和鼠标谁更快捷之争,是一个永远被程序员争论的话题.我想大多数人都不会极端的信奉一种操 ...

  4. zookeeper 学习笔记2

    ephemeral 英[ɪˈfemərəl]美[ɪˈfɛmərəl]adj. 朝生暮死; 短暂的,瞬息的; 朝露; 一年生; ZooKeeper Watcher 机制 集群状态监控示例 为了确保集群能 ...

  5. openfire源码研究笔记:对设计模式及原则的学习

    原文:http://blog.csdn.net/jinzhencs/article/details/50522105 一.拦截器的实现 地点:   package org.jivesoftware.o ...

  6. VUE -- stylus入门使用方法

    sizes() 15px 10px sizes()[0] // => 15px stylus介绍 是个什么鬼?对于开发来说,CSS的弱点在于静态化.我们需要一个真正能提高开发效率的工具,LESS ...

  7. yolo.v2 darknet19结构

    Darknet19( (conv1s): Sequential( (0): Sequential( (0): Conv2d_BatchNorm( (conv): Conv2d(3, 32, kerne ...

  8. leetcode题解:Search for a Range (已排序数组范围查找)

    题目: Given a sorted array of integers, find the starting and ending position of a given target value. ...

  9. python 注释xml的元素

    use xml.dom.minidom 注释xml元素和去除xml注释. code is: #!/usr/bin/env python from xml.dom import minidom impo ...

  10. 命令行设置IE代理

    IE代理可以在注册表中设置,所以用DOS修改注册表,可以达到目的.方法一:注册表文件:REGEDIT4[HKEY_CURRENT_USER\Software\Microsoft\Windows\Cur ...