concept Spring TestContext Framework in category spring

appears as: Spring TestContext Framework
Spring Batch in Action

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.

Listing 14.13. Testing an ItemProcessor with the Spring TestContext Framework

You start by adding a StepScopeTestExecutionListener to create a custom StepExecution with a mandatory parameter in the step scope. You take advantage of the Spring TestContext Framework to autowire the real ItemProcessor .

14.3.1. Introducing the Spring TestContext Framework

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.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest