【发布时间】:2022-01-16 04:50:38
【问题描述】:
我想用假数据模拟数据库调用,但我陷入了以下场景:
我的服务
public class MyService {
// some stuff
Page<SampleDto> sample = repo.findAllSample();
// other stuff
}
我想用when() 存根,但我无法做到这一点。我的测试是:
我的服务测试
public class MySampleTest {
@Test
void myTest() {
// initialisation and all stuff
when(myRepo.findAll()).thenReturn(......)
// I want to pass 2 fake SampleDto from
// here but don't know how to do that
}
}
【问题讨论】:
标签: java unit-testing junit mocking mockito