org.mockito.exceptions.misusing.UnfinishedStubbingException

时间:2015-05-15 17:53:41   收藏:0   阅读:441

问题 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);


原文:http://blog.csdn.net/xiezhongweiwei/article/details/45745039

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!