Date: 2004-05-17T09:15:07
   Editor: 67.166.116.227 <>
   Wiki: DB Torque Wiki
   Page: UnitTestingWithTorque
   URL: http://wiki.apache.org/db-torque/UnitTestingWithTorque

   no comment

New Page:


Unit-testing with Torque can take two forms:

* the DbUnit approach, which actually runs the SQL in a database and determines if the 
correct records are returned;
* testing the contents of the Criteria object

== DbUnit Testing

This is a straight-forward application of the DbUnit package.  It's easy but the 
runtime costs add up, and a lot of the code needed for testing is specific to the 
table being tested.

== Criteria Testing

Unit-testing with the Criteria object is a little tricky but very fast at runtime.  
The main reason this page exists is because I've struggled with one simple fact about 
the Criteria object: the predicate (OR, AND, IN, etc.) information is in a 
package-scoped class.  As a result, my natural tendency to dig around in the Criteria 
object and find what I need has been blocked.  Hmmmm, there must be another way.

Here are a variety of methods for testing the contents of the Criteria class:

* simple assertions
* a helper class devoted to introspecting the Criteria class
* creating a Criteria that the Criteria-under-test should match, and comparing them 
for equality.
* comparing the toString() output of Criteria

=== Simple Assertions

Simple assertions work great unless dealing with a non-trivial query.  They rapidly 
become exercises in understanding the internal construction of the Criteria object, 
which eventually run into the packaged-scope predicate problem.

=== Helper Class

I've been experimenting with a helper class that knows how to introspect the Criteria 
object, but it's an ugly job and of course vulnerable to changes in the Criteria 
class.  Not to mention that once again, the packaged-scope predicates will prevent 
complete testing.

=== Criteria.equal()

Just stumbled on this today, haven't tried it yet.  Could be the elegant solution, if 
equal() is written to ignore ordering issues.

=== Criteria.toString()

Just another untried idea.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to