Java Reference
In-Depth Information
treat testing in the same way I treat flossing: It's a good idea but they either do it
with great reluctance or not at all.
Nevertheless, testing is a key part of the software development process, and just
as flossing prevents dental decay, testing prevents software decay. The persistent
layer, like most other application components, is not immune to decay and so
requires testing. You need to write tests that verify that the domain model is
mapped correctly to the database and that the queries used by the repositories
work as expected. There are two main challenges when testing a persistent
domain model. The first challenge is writing tests that detect the ORM -specific
bugs. These bugs are often caused by inconsistencies between the domain model,
the ORM document, and the database schema. For example, one common mis-
take is to forget to define the mapping for a newly added field, which can cause
subtle bugs. Database constraints are another common problem that prevents the
application from creating, updating, or deleting persistent objects. It's essential to
have tests for the persistent domain model that catch these and other issues.
The second challenge is effectively testing the persistent domain model while
minimizing the amount of time it takes for the tests to run. The test suite for the
O/R mapping of a large domain model can take a long time to execute. Not only
are there a large number of tests but also a test that accesses the database can take
much longer to run than a simple object test. Although some database testing is
unavoidable, it's important to find ways to do testing without it.
In this section you will learn about the different kinds of ORM bugs and how to
write tests to detect them. I describe which aspects of the O/R mapping must be
tested against the database and which other aspects can be tested without a data-
base in order to minimize test execution time. You will see example tests that use
the strategies described here in chapters 5 and 6.
4.5.1
Object/relational testing strategies
A variety of bugs can lurk in the O/R mapping, including the following:
Missing mapping for a field
References to nonexistent tables or columns
Database constraints that prevent objects from being inserted, updated, or
deleted
Queries that are invalid or that return the wrong result
Incorrect repository implementation
 
 
 
Search WWH ::




Custom Search