将@TestExecutionListeners添加到测试套件时,@ test脚本不会为@test运行

时间:2016-06-14 16:59:48

标签: java spring spring-batch junit4

我正在测试一个Spring Batch ItemProcessor,它读取从DB中获取值。

根据Testing Step-Scoped Components页面的建议,我将 @TestExecutionListeners({DependencyInjectionTestExecutionListener.class,StepScopeTestExecutionListener.class})添加到测试套件注释中:

@ContextConfiguration(locations = { "classpath:spring/context-configuration.xml" })
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class })
@RunWith(SpringJUnit4ClassRunner.class)
public class CustomItemProcessorTest 
{
    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;

    @Autowired
    private ItemProcessor<InputClass, OutputClass> customItemProcessor;

    @Test
    @Sql(scripts = {"insertDataToBeRetrievedByCustomItemProcessor.sql" }, 
            config = @SqlConfig(dataSource = "dataSource"))
    public void assertThatCustomItemProcessorProcessorIsRetrievingStillBirthSasEtlObject() throws Exception 
    {
        OutputClass outputObject = customItemProcessor.process(inputClassObject);
    }
}

我遇到的问题是上面一行: @TestExecutionListeners ... 阻止@Sql(scripts = ...命令执行。

customItemProcessor正在轻松地从数据库中读取值。

为什么上面的注释会阻止@Sql脚本运行?如何解决?

1 个答案:

答案 0 :(得分:1)

使用注释 TestExecutionListeners 时,您会超载默认配置 要使您的sql脚本得以执行,您需要添加此侦听器 SqlScriptsTestExecutionListener

View1