spring批处理+ spring boot + java config +测试用例

时间:2017-09-26 22:01:55

标签: spring-boot spring-batch spring-test

spring batch + spring boot + java config + test cases

我已经按照下面的示例和我的用例匹配,我已经实现了类似设置的项目一切正常。

我对编写测试用例感到震惊,有人可能会抛出一些亮点或向我展示编写单元测试用例的方法。

spring batch + spring boot + java config + test cases

     //@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(classes = {JobConfiguration.class,})
@ComponentScan("uk.gov.iebr.batch.processor")
@SpringApplicationConfiguration(classes = IEBRRecommendInterventionsApplication.class)


@RunWith(SpringRunner.class)
@Import(IntegrationTestConfiguration.class)
@SpringBootTest
public class BatchJobRecommendTest {
    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;

    @Autowired
    public DataSource dataSource;

    @Test
    public void testJob() throws Exception {
        JobExecution jobExecution = jobLauncherTestUtils.launchJob();
        Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
        Assert.assertEquals(1, jobExecution.getStepExecutions().size());
    }

    @Test
    public void testStep() throws Exception {
        JobExecution jobExecution = jobLauncherTestUtils.launchStep("step1");
        Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    }




I wrote this test case but , getting Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public javax.sql.DataSource uk.gov.iebr.batch.configuration.JobConfiguration.dataSource; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [javax.sql.DataSource] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.

PLease显示一些directiosn或链接,我可以绘制参考或github代码库,其中实现了similair测试用例......

0 个答案:

没有答案