我想我错过了“thenReturn”部分的语法。我应该为源代码写些什么呢?
下面是源代码:
@Test
public void testGetUserByEmail() {
String email = "mail";
when(storeService.search(Mockito.anyString())).thenReturn(Mockito.any(Store.class));
ModelAndView mav = storeController.search(email);
Assert.assertEquals("userDetail", mav.getViewName());
}
服务是这样的:
public List<Store> listAllStore(){
logger.info("Before add repository to show all");
List<Store> all_stores=(List<Store>) storeRepo.findAll();
logger.info("After add repository to show all");
logger.info(all_stores);
return all_stores;
}
1条答案
按热度按时间l7mqbcuq1#
观察结果很少
when(storeService.search(Mockito.anyString())).thenReturn(Mockito.any(Store.class));
theReturn应该在调用www.example.com()时提供一些实际数据storeService.search。它应该类似于when(storeService.search(Mockito.anyString())).thenReturn(testData);
,其中testData的类型为storeService.search()返回的类型。1.在您的测试用例中,您模拟了
storeService.search()
,但在您的示例中,您提供了listAllStore
的定义。哪一个是正确的?您需要修复您的问题或测试用例。