Return-Path: Mailing-List: contact ibatis-user-java-help@incubator.apache.org; run by ezmlm Delivered-To: mailing list ibatis-user-java@incubator.apache.org Received: (qmail 64499 invoked by uid 99); 14 Feb 2005 17:57:08 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from web202.biz.mail.re2.yahoo.com (HELO web202.biz.mail.re2.yahoo.com) (68.142.224.164) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 14 Feb 2005 09:57:07 -0800 Message-ID: <20050214175705.95627.qmail@web202.biz.mail.re2.yahoo.com> Received: from [69.209.162.188] by web202.biz.mail.re2.yahoo.com via HTTP; Mon, 14 Feb 2005 09:57:05 PST Date: Mon, 14 Feb 2005 09:57:05 -0800 (PST) From: Antony Joseph Subject: Re: Dao unit testing? To: ibatis-user-java@incubator.apache.org In-Reply-To: <1108384566.45453.ezmlm@incubator.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Checked: Checked 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 tables. 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 problem. Check out the Work effort application at http://www.logicden.com 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 > 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 > >