You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Gary Shea <sh...@gtsdesign.com> on 2003/08/15 06:05:43 UTC
unit testing code using torque
I'm wondering what kind of solutions folks have come up with for unit
testing code that uses Torque? I'm just starting to think about it and
have some vague notion of subclassing Torque objects to prevent real db
stuff from happening...
Gary
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: unit testing code using torque
Posted by "Jeffrey D. Brekke" <jb...@brekke.org>.
We've done that using inner classes to prevent save() from actually
doing something to the db. Generally we don't *test* torque generated
classes straight out. But we do write some tests that need the om
objects as fixtures or when we add behavior to them.
I haven't been tracking torque lately, but there was talk of
generating interfaces for all om objects, this way the underlying
implementation could be changed out since you would code to the
interface. This would also allow you to mock ( via
mockobject,easymock,etc ) the generated om interfaces which would be
pretty nice for testing. Not sure if that is possible yet with torque
though.
The other thing is to just blaze up Torque standalone and let it hit a
testing database server. We do this also, but actually going through
the db for all tests will be slow. I'm trying to only do that for a
*few* tests.
>>>>> On Thu, 14 Aug 2003 22:05:43 -0600 (MDT), Gary Shea <sh...@gtsdesign.com> said:
> I'm wondering what kind of solutions folks have come up with for
> unit testing code that uses Torque? I'm just starting to think
> about it and have some vague notion of subclassing Torque objects to
> prevent real db stuff from happening...
> Gary
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For
> additional commands, e-mail: torque-user-help@db.apache.org
--
=====================================================================
Jeffrey D. Brekke jbrekke@wi.rr.com
Wisconsin, USA brekke@apache.org
ekkerbj@yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: unit testing code using torque
Posted by David Hainlin <dh...@comcast.net>.
Hi Gary,
I've done a fair amount of JUnit testing around Torque based projects.
Except in a few specialized classes, I've never found the need to
provide mock torque classes as most of the OM and business related code
really does depend on data Torque is fetching for me. Most of my Torque
Peer extensions have been very straightforward. This type of approach
does require some careful DB planning, and a 'resettable' test database.
Most of my unit tests that work from different levels (say struts mock
objects) either back out any db changes or invoke a 'set up test db'
script. This keeps everything repeatable. On a larger project with
many developers, we had the good fortune to own all of the schema. The
deployment was Oracle but I tested using mySQL with pretty good success.
On projects with less db control and with many developers running unit
tests, I've resorted to id ranging (David gets 1000 through 10000,
Ramesh gets 10000 through 20000, etc...). If you plan ahead, you can
set your 'production' or 'integrated' torque id generation to start
above these levels.
I'm curious about your thoughts on this I'd be interested in hearing
about your experiences.
David
Gary Shea wrote:
>I'm wondering what kind of solutions folks have come up with for unit
>testing code that uses Torque? I'm just starting to think about it and
>have some vague notion of subclassing Torque objects to prevent real db
>stuff from happening...
>
> Gary
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
>For additional commands, e-mail: torque-user-help@db.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: SQL 2 xml
Posted by Sgarlata Matt <sg...@bah.com>.
The jdbc task handles foreign keys properly for me, although this may
depend on the database (I have no idea). I am using Oracle.
One thing about the task is that it doesn't always generate a file that
will correctly generate your torque classes on the first try using the
om task. It wasn't too difficult for me to fix the file that was
generated, so hopefully it won't be for you either. The jdbc task was
definitely a huge time-saver for my project!
Matt
Dave Newton wrote:
> On Sat, 2003-08-16 at 15:12, Sgarlata Matt wrote:
>
>>The jdbc ant task will take care of this for you. Just type
>>
>>ant -f build-torque.xml jdbc
>
>
> Heck, I didn't know that. Thanks! (And thanks for keeping it on the
> list; dangling questions w/o known answers don't help the global
> knowledge pool any!)
>
> Can't check for myself here, but does it correctly handle keys
> (especially foreign) properly?
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
--
Matthew Sgarlata
Senior Consultant
Booz Allen Hamilton Inc.
Work: 703-377-0871
Fax: 703-902-3608
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: SQL 2 xml
Posted by Dave Newton <da...@solaraccess.com>.
On Sat, 2003-08-16 at 15:12, Sgarlata Matt wrote:
> The jdbc ant task will take care of this for you. Just type
>
> ant -f build-torque.xml jdbc
Heck, I didn't know that. Thanks! (And thanks for keeping it on the
list; dangling questions w/o known answers don't help the global
knowledge pool any!)
Can't check for myself here, but does it correctly handle keys
(especially foreign) properly?
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
RE: SQL 2 xml
Posted by Brian Adams <bi...@satx.rr.com>.
Thank you that worked perfectly. :)
Brian
-----Original Message-----
From: Sgarlata Matt [mailto:sgarlata_matt@bah.com]
Sent: Saturday, August 16, 2003 2:12 PM
To: Apache Torque Users List
Subject: Re: SQL 2 xml
The jdbc ant task will take care of this for you. Just type
ant -f build-torque.xml jdbc
and assuming you have Torque configured properly, this will generate the
XML file for you. Here is a full list of all of the ant tasks included
with Torque:
http://db.apache.org/torque/generator/
Matt
Brian Adams wrote:
> Hello Torquers!
> I may have missed this but does Torque have a way to connect to a
database
> and generate a xml schema? In the tutorial it says to type all your
tables
> in xml. I have hundreds of tables that I would like to use Torque as the
om.
> Please help???
> Thanks,
> Brian Adams
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
--
Matthew Sgarlata
Senior Consultant
Booz Allen Hamilton Inc.
Work: 703-377-0871
Fax: 703-902-3608
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: SQL 2 xml
Posted by Sgarlata Matt <sg...@bah.com>.
The jdbc ant task will take care of this for you. Just type
ant -f build-torque.xml jdbc
and assuming you have Torque configured properly, this will generate the
XML file for you. Here is a full list of all of the ant tasks included
with Torque:
http://db.apache.org/torque/generator/
Matt
Brian Adams wrote:
> Hello Torquers!
> I may have missed this but does Torque have a way to connect to a database
> and generate a xml schema? In the tutorial it says to type all your tables
> in xml. I have hundreds of tables that I would like to use Torque as the om.
> Please help???
> Thanks,
> Brian Adams
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
--
Matthew Sgarlata
Senior Consultant
Booz Allen Hamilton Inc.
Work: 703-377-0871
Fax: 703-902-3608
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
SQL 2 xml
Posted by Brian Adams <bi...@satx.rr.com>.
Hello Torquers!
I may have missed this but does Torque have a way to connect to a database
and generate a xml schema? In the tutorial it says to type all your tables
in xml. I have hundreds of tables that I would like to use Torque as the om.
Please help???
Thanks,
Brian Adams
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org