org.mockito.exceptions.misusing.UnfinishedStubbingException

问题 org.mockito.exceptions.misusing.UnfinishedStubbingException:

当我们一个mock方法中继续mock的时候就会跑出异常。比如如下例子

 when(bbbModel.getAAAModel()).thenReturn(AAATest.mocAAAModel())

关键是你在AAATest.mockAAAmodel()方法中继续mock 会的话 就会跑出异常,这与mock的实现机制有关系。(You‘re nesting mocking inside of mocking)

AAATest.mockAAAmodel(){

....

AAA  aaa = mock(AAA.class);

when(aaa.getNames()).thenReturn(Lists.newArrayList("1","2","3","4"));

}

具体问题是mock搞不清楚你到底是在mock aaa.getNames()方法 还是 model.getAAAmodel()方法。

解决办法:

XXXmodel

AAAModel aaaModel = AAATest.mockAAAModel();
when(bbbmodel.getAAAModel()).thenReturn(aaaModel);

时间: 2024-10-24 16:03:49

org.mockito.exceptions.misusing.UnfinishedStubbingException的相关文章

This exception may occur if matchers are combined with raw values

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!3 matchers expected, 2 recorded:-> at com.FilterDeviceReplaceTest.init(FilterDeviceReplaceTest.java:41)-> at com.FilterDeviceReplaceTest.init(FilterDevic

单元测试 - mock异常

最近在使用mock进行单元测试的时候,遇到了下面的问题: org.mockito.exceptions.misusing.InvalidUseOfMatchersException: Invalid use of argument matchers!1 matchers expected, 2 recorded:-> at com.xxx.xxx.clearing.mock.AccountUpdateMock.execute(AccountUpdateMock.java:38)-> at co

编写难于测试的代码的5种方式

本文由码农网 – 孙腾浩原创翻译,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 有一次,我在一个讲座上听到主持人问听众如何故意编写难于测试的代码.在场的小伙伴都惊呆了,因为没有任何人会故意写这种糟糕的代码.我记得他们甚至给不出一个好的答案. 当然,这个问题的目的不在于教大家如何写使同事欲哭无泪的烂代码.而是为了了解什么样的代码难于测试,来避免这些严重的问题. 这里给出我对上面那个问题的答案(当然这只是我的个人观点,每个人讨厌的都不尽相同.) 1.用大量的静态字段 尤其是在不同类中共享静

Distinguish Business Exceptions from Technical

Distinguish Business Exceptions from Technical Dan Bergh Johnsson THERE ARE BASiCALLY TWO REASONS that things go wrong at runtime: technical problems that prevent us from using the application and business logic that prevents us from misusing the app

Catch Application Exceptions in a Windows Forms Application

You need to handle the System.Windows.Forms.Application.ThreadException event for Windows Forms. This article really helped me: http://bytes.com/forum/thread236199.html. Application.ThreadException += new ThreadExceptionEventHandler(MyCommonException

mockito使用心得

前提:pom引用<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version></dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>sprin

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configur

django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. import xadmin时出了这个问

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxError Exception

1.错误描述 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxError Exception:You have an error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near 'notnull,user_name varchar(255) )' at line 1 2.错误原因

Mybatis缓存报错org.apache.ibatis.exceptions.PersistenceException

错误信息如下: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.cache.CacheException: Error deserializing object. Cause: java.lang.ClassNotFoundException: com.kytsoft.model.Adminlink ### Cause: org.apa