title: Spring-Batch: Testing custom itemReader
body: <p>I am trying to test my custom itemReader :</p>
  
  <pre><code>@Bean
  @StepScope
  MyMultiLineItemReader itemReader(@Value("#{stepExecutionContext['fileName']}") String filename) throws MalformedURLException {
  MyMultiLineItemReader itemReader = new MyMultiLineItemReader();
  itemReader.setDelegate(myFlatFileItemReader(filename));
  
  return itemReader;
  }
  
  @Bean
  @StepScope
  public FlatFileItemReader&lt;String&gt; myFlatFileItemReader(@Value("#{stepExecutionContext['fileName']}") String filename) throws MalformedURLException {
  return new FlatFileItemReaderBuilder&lt;String&gt;()
  .name("myFlatFileItemReader")
  .resource(new UrlResource(filename))
  .lineMapper(new PassThroughLineMapper())
  .build();
  }
  </code></pre>
  
  <p>my test class looks like</p>
  
  <pre><code>@Test
  public void givenMockedStep_whenReaderCalled_thenSuccess() throws Exception {
      // given
      JobExecution jobExecution = new JobExecution(5l);
      ExecutionContext ctx = new ExecutionContext();
      ctx.put("fileName", "src/main/resources/data/input.txt");
      jobExecution.setExecutionContext(ctx);
  
      JobSynchronizationManager.register(jobExecution);
      StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(ctx);
  
      // when
      StepScopeTestUtils.doInStepScope(stepExecution, () -&gt; {
       ...
       });
  }
  </code></pre>
  
  <p>When I run the test case, the process fails because the fileName parameter is null.</p>
  
  <p>I am looking for the right way of testing the itemReader.</p>
  
  <p>Thanks</p>