【发布时间】:2018-05-22 13:47:12
【问题描述】:
我正在尝试测试一个执行读取(从另一个应用程序获取数据)过程(简单计算)和写入(到 mongodb)的 spring 批处理作业
读者是@StepScope
这里是读取任务的 postConstruct。
@PostConstruct
public void init(){
employees.addAll(getListOfEmployeesBy(affectationMotifService.findAllRegistrationNumbers()));
}
public List<EmployeeForSalaryDTO> getListOfEmployeesBy(List<String> registrationNumbers){
LOG.debug("request to get all the employees by registration numbers {}" , registrationNumbers);
return coreResourceFeign.getAllEmployeesForSalaryByRegistrationNumbers(registrationNumbers).getBody();
}
当我尝试启动作业测试或应用程序中的任何测试时。 spring 总是运行读取任务的 init() .. 这将导致测试失败,因为我需要模拟 coreResourceFeign.getAllEmployeesForSalaryByRegistrationNumbers(registrationNumbers) 。 我无法模拟该方法,因为它在测试开始之前运行。
这里是测试
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SalaryApp.class, SecurityBeanOverrideConfiguration.class})
public class SalaryJobServiceTest {
@Autowired
@InjectMocks
private SalaryJobService salaryJobService;
@Test
public void startJob() throws Exception {
SalaryJobDTO SalaryJobDTO = salaryJobService.start(Collections.emptyList());
Assert.assertNotNull(salaryJobDTO.getId());
}
}
我不知道如何处理春季批量测试。欢迎任何建议或帮助。
【问题讨论】:
标签: java spring spring-boot junit spring-batch