> From: "Jim Jackl-Mochel" <jmochel@...>
> Subject: Unit Testing JDBC database code.
> In trying to make my unit tests very self contained I have
> come up against a
> headache. In the case of those classes that read or
> manipulate a database
> via JDBC I
> would ideally like to create the database, manipulate it, and
> then remove
> the database.
> How have everybody else handled this sort of unit test ?
I have created java interfaces that encapsulate the queries I need to make.
The normal implementation of those interfaces is the code that knows about
JDBC, the schema, etc. My unit tests also implement those interfaces and
pretend to act like the database. They supply and accept the necessary data
and verify that the database is handled correctly. This also allows me to
mimic database errors.
See the "MockObject" threads on email@example.com
. Also see
the book "Extreme Programming In Practice" by Jim Newkirk and Robert C.
Robert C. Martin | "Uncle Bob" | Software Consultants
Object Mentor Inc. | rmartin@...
| We'll help you get
PO Box 5757 | Tel: (800) 338-6716 | your projects done.
565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com
Suite 135 | | www.XProgramming.com
Vernon Hills, IL, | Training and Mentoring | www.junit.org
60061 | OO, XP, Java, C++, Python|
"One of the great commandments of science is:
'Mistrust arguments from authority.'" -- Carl Sagan