-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
has: minimal-exampleBug reports that provide a minimal complete reproducible exampleBug reports that provide a minimal complete reproducible examplein: testtype: bug
Description
Discussed in #4518
Originally posted by heitormsilva December 16, 2023
Hi.
I have a configuration like this: job -> step (outerStep) -> flow (outerFlow) -> flow (innerFlow) -> step (innerStep).
I want to run a integration test of the innerStep, but I get a "java.lang.IllegalStateException: No Step found with name: [innerStep]".
If I run the test pointing to outerStep it works.
My test class is annotated with @SpringBootTest and @SpringBatchTest.
I'm running the step with: jobLauncherTestUtils.launchStep("innerStep");
How can I call only the innerStep?
Metadata
Metadata
Assignees
Labels
has: minimal-exampleBug reports that provide a minimal complete reproducible exampleBug reports that provide a minimal complete reproducible examplein: testtype: bug
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
HyunSangHan commentedon May 8, 2025
I can take a look at this! 👀
fmbenhassine commentedon May 8, 2025
@HyunSangHan Sure! Thank you for your offer to help!
As I mentioned in the initial discussion, this seems like a bug to me. The test utility should be able to locate the step no matter how deep it is in the flow. Please let me know if you need help on this.
HyunSangHan commentedon May 12, 2025
Let me first share what I’ve understood so far about the issue like below:
(If I got anything wrong, feel free to let me know.)
spring-batch/spring-batch-test/src/main/java/org/springframework/batch/test/JobLauncherTestUtils.java
Line 234 in c6f88b8
When calling
getStep(stepName)
, it looks for a step with the given name among the available steps.At this point, only the
outerStep
is typically included in the list of steps(innerStep
is usually not).However, there's only one condition where we get a chance to retrieve steps inside another step (like
innerStep
withinouterStep
).spring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleJob.java
Lines 103 to 108 in c6f88b8
But in the code, this only happens if the
outerStep
implementsStepLocator
.If it doesn't, we miss that opportunity.
From what I can tell, classes like
FlowStep
(used asouterStep
) do not implementStepLocator
, so their inner steps are not exposed—leading to this issue.HyunSangHan commentedon May 24, 2025
@fmbenhassine
I’ve taken a closer look at this issue and I have two ideas to enable reading inner steps.
The first idea is to have the abstract class
AbstractStep
implementStepLocator
. I believe this is a more fundamental solution because inner steps can only be included in the steps managed by the outer step if the outer step is an instance ofStepLocator
. However, the downside is that all steps extendingAbstractStep
would need to implement the methods ofStepLocator
.The second idea is to inject
applicationContext
as a dependency intoJobLauncherTestUtils
and use thegetBean
method to retrieve the step by looking up the bean corresponding to the inner step’s name. This would involve relatively less code modification, but I feel this may not be a good pattern since it relies on fetching the bean fromapplicationContext
.Considering these two approaches, I believe the first idea would be a better solution to this issue.
I’d like to hear your thoughts on this.