3
我有一個Spring Boot Batch應用程序,我正在編寫集成測試。當我執行測試時,整個批處理應用程序將運行。我怎樣才能執行測試中的應用程序代碼?如何防止我的Spring Boot Batch應用程序在執行測試時運行?
這是我的測試代碼。執行時,整個批處理作業步驟將運行(讀取器,處理器和寫入器)。然後,測試運行。
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BatchApplication.class))
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
StepScopeTestExecutionListener.class })
public class StepScopeTestExecutionListenerIntegrationTests {
@Autowired
private FlatFileItemReader<String> reader;
@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
public StepExecution getStepExection() {
StepExecution execution = MetaDataInstanceFactory.createStepExecution();
return execution;
}
@Test
public void testGoodData() throws Exception {
//some test code on one met
File testFile = testFolder.newFile();
PrintWriter writer = new PrintWriter(testFile, "UTF-8");
writer.println("test");
writer.close();
reader.setResource(new FileSystemResource(testFile));
reader.open(getStepExection().getExecutionContext());
String test = reader.read();
reader.close();
assertThat("test", equalTo(test));
}
}
該應用程序已在使用/src/main/resources/application.yml。有沒有辦法指向不同的配置文件進行測試? – James
除了把一個放在'src/test/resources'中? –
是的,我試着把它放在src/test/resources中。現在,在測試和常規應用程序運行期間,該作業被禁用。 – James