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