Open marschall opened 3 years ago
I'm afraid, it's not a bug but a feature. 😄 The javadoc on JobScopeTestExecutionListener#getJobExecution
is indeed misleading but the comment on class level is correct. And it's also described in the reference documentation: https://docs.spring.io/spring-batch/docs/4.3.x/reference/html/testing.html#testing-step-scoped-components
I was also quite surprised when I stumbled on this in a similar manner, and I'm not sure whether it's a good idea that the listeners are added with @SpringBatchTest
automatically. In particular, since there is no straight-forward way to disable them, if I still want the beans from BatchTestContextCustomizer
.
Maybe an annotation like e.g. @TestJobExecution
on the method would be a sensible requirement for users to enable this feature.
Bug description
JobScopeTestExecutionListener
invokes any method with theJobExecution
return type. Consider the following test with uses a utility method to launch a job. The method will be invoked byJobScopeTestExecutionListener
before the@BeforeEach
and@Test
method. In this case causing the test to fail because thejobParameters
isnull
.Environment Spring Batch version: 4.3.3 Java version: 11.0.12 Database: H2 1.4.200
Steps to reproduce
JobScopeTestExecutionListener
, for example by adding@SpringBatchTest
JobExecution
, can have any number of argumentsExpected behavior
org.springframework.batch.test.JobScopeTestExecutionListener#getJobExecution(TestContext)
looks only at fields as the comment says.Minimal Complete Reproducible example