这是我需要为其编写测试的主文件中的函数。
@Override
public void processTask(JobExecutionContext arg0) throws TaskException {
if (BatchInputChannel.DB.toString().equals(runtimeContext.getProperties().getProperty(BATCH_CHANNEL_TYPE))) {
return;
} else if (BatchInputChannel.FILE.toString().equals(runtimeContext.getProperties().getProperty(BATCH_CHANNEL_TYPE))) {
jobLauncher = (JobLauncher) beanFactory.getBean("jobLauncher");
Job job = (Job) beanFactory.getBean("micorpFileLoadJob");
JobParameters jobParameters = new JobParametersBuilder()
.addLong("time", System.currentTimeMillis())
.toJobParameters();
try {
JobExecution jobExecution = jobLauncher.run(job, jobParameters);
System.out.println("jobExecution=="+jobExecution);
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException e) {
throw new ProcessingException("File Loading Failed" + e.getMessage());
}
}
}
这是我试图创建的测试函数
@Test(expected = JobParametersInvalidException.class)
public void processTaskWithFileInputJobFailed5() throws Exception {
when(mockruntimeContext.getProperties()).thenReturn(mockProperties);
when(mockProperties.getProperty(BATCH_CHANNEL_TYPE)).thenReturn("FILE");
when(mockbeanFactory.getBean("jobLauncher")).thenReturn(mockJobLauncher);
when(mockbeanFactory.getBean("micorpFileLoadJob")).thenReturn(mockjob);
}
当我将项目作为 J 单元测试执行时,它期望抛出处理异常,但我在预期中提到了“JobParametersInvalidException”。
如您所见,我在此函数中只添加了一个异常,为了覆盖主函数中的所有异常(在 catch 内)需要做什么?
慕尼黑的夜晚无繁华
相关分类