44 lines
3.1 KiB
HTML
44 lines
3.1 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>End-To-End Testing of Batch Jobs</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="ch10.xhtml" title="Chapter 10. Unit Testing"/><link rel="next" href="ch10s03.xhtml" title="Testing Individual Steps"/></head><body><header/><section class="section" title="End-To-End Testing of Batch Jobs" epub:type="subchapter" id="endToEndTesting"><div class="titlepage"><div><div><h2 class="title" style="clear: both">End-To-End Testing of Batch Jobs</h2></div></div></div><p>'End To End' testing can be defined as testing the complete run of a
|
||
batch job from beginning to end. This allows for a test that sets up a
|
||
test condition, executes the job, and verifies the end result.</p><p>In the example below, the batch job reads from the database and
|
||
writes to a flat file. The test method begins by setting up the database
|
||
with test data. It clears the CUSTOMER table and then inserts 10 new
|
||
records. The test then launches the <code class="classname">Job </code>using the
|
||
<code class="methodname">launchJob()</code> method. The
|
||
<code class="methodname">launchJob</code>() method is provided by the
|
||
<code class="classname">JobLauncherTestUtils</code> class. Also provided by the
|
||
utils class is <code class="classname">launchJob(JobParameters)</code>, which
|
||
allows the test to give particular parameters. The
|
||
<code class="methodname">launchJob()</code> method returns the
|
||
<code class="classname">JobExecution</code> object which is useful for asserting
|
||
particular information about the <code class="classname">Job</code> run. In the
|
||
case below, the test verifies that the <code class="classname">Job</code> ended
|
||
with status "COMPLETED".</p><pre class="programlisting">@RunWith(SpringJUnit4ClassRunner.class)
|
||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml",
|
||
"/jobs/skipSampleJob.xml" })
|
||
public class SkipSampleFunctionalTests {
|
||
|
||
@Autowired
|
||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||
|
||
private SimpleJdbcTemplate simpleJdbcTemplate;
|
||
|
||
@Autowired
|
||
public void setDataSource(DataSource dataSource) {
|
||
this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
|
||
}
|
||
|
||
@Test
|
||
public void testJob() throws Exception {
|
||
simpleJdbcTemplate.update("delete from CUSTOMER");
|
||
for (int i = 1; i <= 10; i++) {
|
||
simpleJdbcTemplate.update("insert into CUSTOMER values (?, 0, ?, 100000)",
|
||
i, "customer" + i);
|
||
}
|
||
|
||
JobExecution jobExecution = jobLauncherTestUtils.launchJob().getStatus();
|
||
|
||
|
||
Assert.assertEquals("COMPLETED", jobExecution.getExitStatus());
|
||
}
|
||
}</pre></section><footer/></body></html> |