14 lines
2.5 KiB
HTML
14 lines
2.5 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Chapter 10. Unit Testing</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch09s05.xhtml" title="Declarative Retry"/><link rel="next" href="ch10s02.xhtml" title="End-To-End Testing of Batch Jobs"/></head><body><header/><section class="chapter" title="Chapter 10. Unit Testing" epub:type="chapter" id="testing"><div class="titlepage"><div><div><h1 class="title">Chapter 10. Unit Testing</h1></div></div></div><p>Just as with other application styles, it is extremely important to
|
||
unit test any code written as part of a batch job as well. The Spring core
|
||
documentation covers how to unit and integration test with Spring in great
|
||
detail, so it won't be repeated here. It is important, however, to think
|
||
about how to 'end to end' test a batch job, which is what this chapter will
|
||
focus on. The spring-batch-test project includes classes that will help
|
||
facilitate this end-to-end test approach.</p><section class="section" title="Creating a Unit Test Class" epub:type="subchapter" id="creatingUnitTestClass"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Creating a Unit Test Class</h2></div></div></div><p>In order for the unit test to run a batch job, the framework must
|
||
load the job's ApplicationContext. Two annotations are used to trigger
|
||
this:</p><div class="itemizedlist" epub:type="list"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem" epub:type="list-item"><p><code class="classname">@RunWith(SpringJUnit4ClassRunner.class)</code>:
|
||
Indicates that the class should use Spring's JUnit facilities</p></li><li class="listitem" epub:type="list-item"><p><code class="classname">@ContextConfiguration(locations = {...})</code>:
|
||
Indicates which XML files contain the ApplicationContext.</p></li></ul></div><pre class="programlisting">@RunWith(SpringJUnit4ClassRunner.class)
|
||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml",
|
||
"/jobs/skipSampleJob.xml" })
|
||
public class SkipSampleFunctionalTests { ... }</pre></section></section><footer/></body></html> |