org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue
错误原因:mock的时候,不能mock重载的方法
解决方法:直接mock它的父类的方法
org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue:
'flush' is a *void method* and it *cannot* be stubbed with a *return value*!
Voids are usually stubbed with Throwables:
doThrow(exception).when(mock).someVoidMethod();
***
If you're unsure why you're getting above error read on.
Due to the nature of the syntax above problem might occur because:
1. The method you are trying to stub is *overloaded*. Make sure you are calling the right overloaded version.
2. Somewhere in your test you are stubbing *final methods*. Sorry, Mockito does not verify/stub final methods.
3. A spy is stubbed using when(spy.foo()).then() syntax. It is safer to stub spies -
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
4. Mocking methods declared on non-public parent classes is not supported.
org.mockito.exceptions.misusing.CannotStubVoidMethodWithReturnValue的更多相关文章
- 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中的a ...
- 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,首先需要在我们工程中引 ...
- 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 ...
- 基于spring-boot的应用程序的单元+集成测试方案
目录 概述 概念解析 单元测试和集成测试 Mock和Stub 技术实现 单元测试 测试常规的bean 测试Controller 测试持久层 集成测试 从Controller开始测试 从中间层开始测试 ...
- Powermockito 针对方法中new 对象的模拟,以及属性中new 对象的模拟
PowerMocker 是一个功能逆天的mock 工具. 一,Powermockito 针对方法中new 对象的模拟 // 如何才能mock掉 WeChatConfigUtil 这个类,让 weCha ...
- 【项目经验】Mockito教程
一.教程 转载:https://blog.csdn.net/sdyy321/article/details/38757135/ 官网: http://mockito.org API文档:http:// ...
- spring-boog-测试打桩-Mockito
Mockito用于测试时进行打桩处理:通过它可以指定某个类的某个方法在什么情况下返回什么样的值. 例如:测试 controller时,依赖 service,这个时候就可以假设当调用 service 某 ...
随机推荐
- Problem L: 输出200-299之间的所有素数
#include<stdio.h> #include<math.h> int main() { int count,m,n,i; count=; ;m<;m++) { n ...
- iOS开发-设置在使用NavigateController时View的顶部位置
最近我在开发中遇到了一个问题,在使用NavigationController时内部的ViewController的View总是与屏幕顶部对齐,而我们有时候不需要这种效果: 在开发过程中,我们可能会 ...
- mysql 中查询一个字段是否为null的sql
查询mysql数据库表中字段为null的记录: select * 表名 where 字段名 is null 查询mysql数据库表中字段不为null的记录: select * 表名 where 字段名 ...
- C++11简要介绍
概述 C++1x (本教程中指 C++11/14, 甚至 C++17) 为传统 C++ 注入的大量特性使得整个 C++ 变得更加像一门现代化的语言.C++1x 不仅仅增强了 C++ 语言自身的可用性 ...
- DEB方式在UBUNTU安装ODOO 8.0
odoo在ubuntu最简单最快速安装方式是deb方式,基本无需再去改数据库配置文件,全自动化了,odoo中文网推荐新手采用此方法 1 安装数据库:sudo apt-get install postg ...
- 【Android Studio探索之路系列】之中的一个:Android Studio开篇
作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...
- 取给定正整数的指定bit位開始的指定长度的数据
接口说明 原型: unsigned int GetBitsValue(unsigned int input, unsigned int startbit, unsigned int bitlen) 输 ...
- detach与remove区别,以及detach保留被删除的元素数据,使用
detach() 会保留所有绑定的事件.附加的数据,这一点与 remove() 不同. remove掉元素后,元素再也找不回了.但是detach还能找回来,还能保留下来. 实现方式如下代码: < ...
- Oracle 和sqlserver 字符串补齐
Oracle:Lpad函数 语法格式如下: lpad( string, padded_length, [ pad_string ] ) string 准备被填充的字符串: padded_length ...
- jquery 事件:2
unbind(type [,data]) //data是要移除的函数 $('#btn').unbind("click"); //移除click $('#btn').unbi ...