I'm not familiar with Cucumber, but I have instantiated/tested step scope items using @RunWith(SpringJUnit4ClassRunner.class)
I would recommend including the StepScopeTestExecutionListener.class
as well as the DependencyInjectionTestExecutionListener
(if you're injecting any dependencies) in your @TestExecutionListeners
annotation, e.g. @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class })
In order to instantiate a step scope bean in the test class, first get an instance of the ExecutionContext
by utilizing the MetaDataInstanceFactory
.
For example:
ExecutionContext executionContext = MetaDataInstanceFactory.createJobExecution().getExecutionContext();
Once you can have an instance of the ExecutionContext
, you'll need to make use of the JobLauncherTestUtils
class (documentation: http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/test/JobLauncherTestUtils.html). You can launch a step by calling launchStep()
, for example:
jobLauncherTestUtils.launchStep(<step_name>, <job_parameters>, <execution_context>);
Hope that helps!