问题描述
有没有其他方法可以为下面的案例编写测试用例,需要为 runStudentService 方法编写测试用例。尝试编写如下测试用例,但它抛出:“想要但未调用 - 实际上,与此模拟的交互为零。”
@Component
public class StudentScheduler {
@Autowired
private StudentService studentService;
@Scheduled(cron = "${cron.students}")
public void runStudentService() {
try {
studentService.startStudetstest();
} catch (Exception e) {
LOG.error("Error occured during test" + e);
throw(e);
}
}
}
@RunWith(SpringJUnit4ClassRunner.class)
public class StudentSchedulerTest {
@Mock
private StudentService studentService;
StudentScheduler scheduler = Mockito.mock(StudentScheduler.class);
@Test
public void jobRuns() {
Mockito.donothing().when(scheduler).runStudentService();
verify(scheduler,Mockito.times(1)).runStudentService();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)