ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antony Joseph <ajos...@logicden.com>
Subject Re: Dao unit testing?
Date Mon, 14 Feb 2005 17:57:05 GMT
Here is how I do it using Dbunit. Its slightly
involved but if I had to choose one layer to test, I
will always choose the data access layer.

1) The test data for the test suite should include all
pertinent data including data for the foreign key
2) Follow a consistent naming convention for foreign
key data so that when mutliple tests are run you don't
get data integrity violations.
3) Clean all the pertinent tables (including the
foreign key ones) for the test. I normally take the
easy route and just clean all the tables in
application before a test suite is run. When working
within a team this is a problem unless every one works
with their own local database. If you have foreign key
relationships avoid using dbunit options like
DELETE_INSERT or REFRESH. Invariably you will run into
violations when running multiple test.
4) Create a seperate class for test parameters. This
helps, if you want to invoke your daos from other
layers in an integration test or for load tests. For
example I use the same parameters when testing a
struts controller using StrutsTestCase.
5) I generally don't cleanup the test data after a
test. This way its easier to figure out the problem if
something goes wrong. 
6). Make sure you use p6spy with Dbunit (Instructions
are at dbunit site). It will log the SQL statements 
dbunit is invoking, so if something goes wrong during
the loading of the data you can quickly identify the

Check out the Work effort application at

I just released it under the Apache licence. Take a
look at the test suites for the Service layer. The
application uses Spring to manage transactions instead
of iBATIS dao, but it should give you an idea on how I
am testing the data access  code.

> Date: Thu, 10 Feb 2005 08:41:43 -0700
> From: Nathan Maves <Nathan.Maves@Sun.COM>
> Subject: Dao unit testing?
> To: ibatis-user-java@incubator.apache.org
> I have been trying for two day to get DBunit to work
> with only partial 
> success.  The support for this project is
> nonexistent.  Anyone know of 
> a more supported project or have any experience with
> this one?  How do 
> most of you test your database layer?
> Nathan

View raw message