如何用@JobScope
模拟替换Mockito
'
我正在尝试以下方法:
@RunWith(SpringRunner.class)
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, JobScopeTestExecutionListener.class})
public class MyBrokenTest {
@Autowired
public ValueObject myJobScopedBean;
@Test
public void doStuff() throws Exception {
myJobScopedBean.setVaue(new TestObject());
JobExecution jobExecution = jobLauncherTestUtils.launchStep("myCoolTasklet", getJobExecution().getExecutionContext());
}
}
但没有成功。在步骤内,myJobScopedBean
的新值未初始化。据我所知,JobScopeTestExecutionListener
并不打算与jobLauncherTestUtils
一起使用,这是正确的吗?如何使用模拟依赖项测试我的步骤?
UPD。
配置也很简单:
@Configuration
@EnableBatchProcessing
public class MyJobConfig {
/* ... Job definition ... */
@Bean
@JobScope
public Tasklet getMyCoolTasklet(MyJobScopedBean myJobScopedBean) {
return new MyCoolTasklet(myJobScopedBean);
}
@Bean
@JobScope
public MyJobScopedBean myJobScopedBean() {
return new MyJobScopedBean();
}
}