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 does not work ootb with SpringBoot #4233
Comments
Thank you for opening this ticket. This is a valid issue, and is related to the new way test utilities are configured with Now on the Boot side, things are a bit different with regard to the setup of the test context. I noticed that without importing the Could you please give the latest snapshots a try? I am expecting the following test to pass with the latest snapshots: import org.junit.jupiter.api.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.batch.test.context.SpringBatchTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBatchTest
@SpringBootTest
public class HelloBatchTest {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
@Test
public void testHello() throws Exception {
var jobExecution =
jobLauncherTestUtils.launchJob();
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}
} |
I can confirm that the test passes, but it runs the job twice. (The JobLauncher from the AutoConfiguration...) I added @SpringBootTest
@SpringBatchTest
@TestPropertySource(properties = "spring.batch.job.enabled=false")
public class HelloBatchTest { then everything is fine. Maybe this should be the default in a test? |
Thank you for taking the time to test the fix! Much appreciated 👍
This is not specific to Spring Batch per se. Please check/request this with the Boot team. Thank you upfront. |
Given the following job definition with Spring Boot 3-RC2:
The following test (as suggested in the javadoc) does fail:
the exception goes here
I could workaround by making the test a SpringBootTest and disabling the auto-configured joblauncher but i guess that is not the intented solution.
The text was updated successfully, but these errors were encountered: