-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpringBatchTest should support application contexts without javax.sql.DataSource #3767
Comments
I do confirm this issue, here is a failing test with v4.3.3: import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.batch.test.context.SpringBatchTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
@SpringBatchTest
@RunWith(SpringRunner.class)
public class springBatchTestWithoutDataSource {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
public void testJob() throws Exception {
JobExecution jobExecution = jobLauncherTestUtils.launchJob();
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
}
@Configuration
@EnableBatchProcessing
public static class JobConfiguration {
@Bean
public Job job(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
return jobBuilderFactory.get("job")
.start(
stepBuilderFactory.get("step")
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.build())
.build();
}
}
} This is not directly related to the Since the Map-based job repository has been deprecated for removal (see #3780), we need to revisit how this should work in v5 (it might be fixed by design since a datasource will be mandatory). |
Hi, do we have update on this enhancement |
@munnema you could have a look at spring-batch-inmemory that gives you a |
Hi @marschall |
@munnema maybe it's better to raise an issue in that project and keep the discussion on this issue on topic |
Hi @fmbenhassine, Is there any workaround on spring-batch 2.7.2 to unit test jobs and steps without needing DataSource ? Thank you. |
@oha85 This issue is closed. Please check https://github.com/spring-projects/spring-batch#getting-help for how to ask for support and I will try to help. Thank you. |
No indication how to implement the test case where DataSource is used or DataSource No qualifying bean of type is coming |
With Batch 5 it's now easily possible to write integration tests that do not need a An example can be found here: Or here: |
Spring-batch has 2 annotations to simply context creation
EnableBatchProcessing
SpringBatchTest
EnableBatchProcessing support's app contexts without
javax.sql.DataSource
bean. It's mentioned in javadochttps://github.com/spring-projects/spring-batch/blob/4.2.x/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.java#L88
SpringBatchTest doesn't support contexts without
javax.sql.DataSource
and fails withThe text was updated successfully, but these errors were encountered: