Java Reference
In-Depth Information
C H A P T E R 12
Testing Batch Processes
Testing: everyone's favorite part of programming. The funny thing is, like most things in life, once you
get good at it, testing actually is fun. It allows you to be more productive. It provides a safety net for you
to try new things. Programmatic tests also give you a test bed to try new technologies (most companies
don't mind if you want to try something new in the tests but mind greatly if you try it in code that's going
to production). You've spent the previous 10 chapters writing code without the ability to prove that any
of it works. This chapter looks at how to exercise your code in a variety of ways so you can not only prove
that it works as designed, but also provide a safety net for when you change it.
This chapter covers the following topics:
Unit tests with JUnit and Mockito : You begin with a high-level overview of the
JUnit and Mockito frameworks. Although you move past JUnit's base functionality
in the later parts of the chapter, the concepts that Spring has incorporated into its
testing apparatus are based in the JUnit conventions, so knowing them helps you
understand what is going on in the more advanced tests. The chapter also covers
how the mock object framework Mockito can help you unit-test the components
you develop for your batch processes.
Integration testing with Spring's test framework : Spring has done to testing what
it's done to most other harder Java tasks: made it easy. It provides a collection of
classes that allow you to easily test interactions with your various resources
(databases, files, and so on) with minimal overhead. You learn how to use the
Spring testing components to test various aspects of your Spring Batch jobs.
The most fundamental aspect of testing begins with unit testing, so the discussion begins there.
Unit Tests with JUnit and Mockito
Probably the easiest to write and perhaps the most valuable, unit tests are the most overlooked type of
testing. Although the development done in this topic hasn't taken a test-driven approach for a number
of reasons, you're encouraged to do so in your own development. As a proven way to improve not only
the quality of the software you produce but also the overall productivity of any individual developer and
a team as a whole, the code encased in these tests is some of the most valuable you can produce. This
section looks at how to use JUnit and Mockito to unit-test the components you develop for your batch
processes.
What is a unit test? It's a test of a single, isolated component in a repeatable way. Let's break down
that definition to understand how it applies to what you're trying to do:
A test of a single: One. Unit tests are intended to test the smallest building blocks of
your application. A single method is typically the scope of a unit test.
 
Search WWH ::




Custom Search