You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Brian Kierstead <br...@fluidmedia.com> on 2007/02/16 19:35:43 UTC

iBatis and Unit Testing

Hello,

We are currently implementing unit testing on our team and trying to 
figure out how to do it.  We use ibatis, both the dao and mapper, and 
layers similar to the npetshop project.  We want to test our persistence 
layer, but we're stuck on how to do it since the dao is instantiated in 
the service layer.  What are others doing?  We've talked about 
replicating the entire service layer, along with the config files for 
ibatis, but that seems like a lot do.

Thanks!

B


Re: iBatis and Unit Testing

Posted by Clinton Begin <cl...@gmail.com>.
You might want to have a look at JPetStore.  Although it's Java, you might
get some ideas.

JPetStore uses the DAO and Mapping layers and achieves a 92% coverage
(really only exceptions aren't tested by choice/laziness).  ;-)

Also consider organizing your tests into Unit, Persistence and Integration.

Unit Tests are self contained, very fast to run and don't require any
external resources like connections to a database or files.  To run your
entire Unit Test project should take less than one minute (we routinely are
able to run over 1000 unit tests in less than a minute).  Use a Mock
framework to mock the DAOs and Service layer of your application.  Your
classes should have two constructors:  One should be parameterless and
instantiate the service or DAO.  The other should take the Service or DAO as
a parameter -- thus enabling you to pass in a mock.

Persistence Tests are allowed to access a test instance of your database.
This is how you test your SQL and Stored Procs.  Hence, this is also how you
test your iBATIS SQL Maps.  The persistence suite should drop and rebuild
the database (DDL), as well as load up the test data.  These tests may take
longer than one minute, but should still run reasonably fast -- still shoot
for one minute, but a few minutes is acceptable.

Integration Tests are allowed to access test instances of dependent servers,
files, web services, databases or test instances of other applications.
These tests may take a lot longer depending on the dependencies, especially
one's you can't control.  Sometimes if they take too long, we'll only run
them as part of the CI build, not necessarily on every developer's
workstation.

So check out JPetStore, and you might even want to pick up a copy of iBATIS
in Action, as it does explain some of this (although in a Java context).

Cheers,
Clitnon



Clinton


On 2/16/07, Brian Kierstead <br...@fluidmedia.com> wrote:
>
> Hello,
>
> We are currently implementing unit testing on our team and trying to
> figure out how to do it.  We use ibatis, both the dao and mapper, and
> layers similar to the npetshop project.  We want to test our persistence
> layer, but we're stuck on how to do it since the dao is instantiated in
> the service layer.  What are others doing?  We've talked about
> replicating the entire service layer, along with the config files for
> ibatis, but that seems like a lot do.
>
> Thanks!
>
> B
>
>

RE: iBatis and Unit Testing

Posted by Ross Owen <rl...@firstam.com>.
We have implemented NUnit with this... you do have to duplicate the config files - ours is asp.net, so we create an app.config file as well as the properties.config we use for sql configuration for iBatis.
 
We do all of this with a NAnt task.
 
If you figure out a better way to do this, I'm open, but NAnt is very nice and does it for us (only a one time setup).
 
-Ross

________________________________

From: Brian Kierstead [mailto:brian@fluidmedia.com]
Sent: Fri 2/16/2007 11:35 AM
To: user-cs@ibatis.apache.org
Subject: iBatis and Unit Testing



Hello,

We are currently implementing unit testing on our team and trying to
figure out how to do it.  We use ibatis, both the dao and mapper, and
layers similar to the npetshop project.  We want to test our persistence
layer, but we're stuck on how to do it since the dao is instantiated in
the service layer.  What are others doing?  We've talked about
replicating the entire service layer, along with the config files for
ibatis, but that seems like a lot do.

Thanks!

B

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________