Java Reference
In-Depth Information
i BATIS is all about best practices—it is largely the reason i BATIS was created. For
starters, i BATIS helps you maintain separation of concerns between your applica-
tion and the persistence layer. It also helps you avoid mixing Java and SQL and
ending up with a mess of twisted code. i BATIS lets you separate the design of your
object-oriented domain model from your relational data model. This chapter dis-
cusses a number of best practices that will help you get the most out of i BATIS .
13.1 Unit testing with iBATIS
Unit testing has become a very important part of modern
software development methodologies. Even if you don't
subscribe to the benefits of extreme programming or
other agile methods, unit testing should be a cornerstone
practice in your software development life cycle.
Conceptually, the persistence tier is separated into
three layers, and i BATIS makes it easy to unit-test those lay-
ers, as illustrated in figure 13.1.
i BATIS facilitates testing these layers in at least three
ways:
DAO Consumer
Persistence Logic
Testing the mapping layer itself, including the map-
pings, SQL statements, and the domain objects
they're mapped to
SQL Mapping
Figure 13.1 These
are the typical layers
immediately involved
with persistence
(nonpersistence-related
layers are not shown in
this diagram).
Testing the DAO layer, which allows you to test any
persistence specific logic that may be in your DAO
Testing within the DAO consumer layer
13.1.1
Unit-testing the mapping layer
This is generally the lowest level of unit testing that will take place in most
applications. The process involves testing the SQL statements and the domain
objects they're mapped to as well. This means that we'll need a database instance
to test against.
The test database instance
The test database instance might be a true instance of a database that you're actu-
ally using, such as Oracle or Microsoft SQL Server. If your environment is friendly
to unit testing, then this is a simple option to get up and running. Using real data-
bases might be necessary if you're planning to take advantage of nonstandard
Search WWH ::




Custom Search