concept Spring TestContext Framework in category spring

This is an excerpt from Manning's book Spring Batch in Action.
The test uses the Spring TestContext Framework, which creates a Spring application context during the test and lets you inject some Spring beans into the test (with the @Autowired annotation). The @RunWith and @ContextConfiguration trigger the Spring TestContext Framework. Chapter 14 is all about testing, so give it a read if you want to learn more about this topic. At
, you clean and populate the database. This creates a consistent database environment for each @Test method. At
, you launch the job with its parameters and check at
that the job correctly inserted the products from the test ZIP archive. The test ZIP archive doesn’t have to contain thousands of records: it can be small so the test runs quickly.
To go on with integration testing of our case study, we introduce the Spring TestContext Framework and the Spring Batch StepScopeTestExecutionListener class. To track what you’re testing, please refer to figure 14.3. We focus next on testing instances of Step, ItemReader, and ItemProcessor.
The Spring Framework provides support for integration testing with the Spring TestContext Framework, which lets you write tests for a framework like JUnit. In JUnit, the @RunWith annotation sets a Runner class, which is responsible for launching tests, triggering events, and marking tests as successful or failed.