This sounds about like what I was expecting, I was just trying to make a nice simple test that tested one function rather than testing create and read all at the same time. However, I think I would prefer doing this rather than writing queries directly against the database for validation as if the schema changed, then the changes would have to be made in both the dao and the test.
As far as testing against live data, hopefully these tests would never be run on a live database. Paul's suggestion about using cftransaction was interesting, but depending on the database type, I use cftransaction to capture auto incrementing id values.
Thanks for the pointers.
-- Jeff
On 11/27/05, Jeff Chastain <[EMAIL PROTECTED]>wrote:
> What would a unit test (either CFUnit or CFCUnit) look like for a DAO
> object? For example, would the test for the the create function pass in a
> bean, then call the read method and somehow compare the returned bean with
> the original bean? Does anybody have an example of a unit test for a DAO?
Well, there are a lot of answers to this... I asked Rob Blackburn
about DB testing and got an essay back in response. A lot depends on
exactly what you are trying to test.
You could:
a) write the test to just call create / read / update / delete methods
on the DAO and check that you get back expected results (create an
object and read it back, update an object and read it back, delete an
object and ensure you get an error trying to read it back)
b) write the test to call CRUD methods but then do a raw select query
to test what is actually in the data
c) write the test to manipulate the database with raw CRUD queries and
then call the CRUD DAO methods
d) ... probably other options ...
Personally, I'd go with (a) so the test case does not need to know
about the database but there are certain situations where both (b) and
(c) might be useful.
Bear in mind also that most DB-related testing is history-sensitive,
i.e., your tests affect the database in ways that might also affect
your application.
--
Sean A Corfield -- http://corfield.org/
Got frameworks?
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.
CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).
An archive of the CFCDev list is available at www.mail-archive.com/[email protected]
- Re: [CFCDev] Unit Test for DAO Jeff D . Chastain
- RE: [CFCDev] Unit Test for DAO Hugo Ahlenius
- Re: [CFCDev] Unit Test for DAO Paul Kenney
- Re: [CFCDev] Unit Test for DAO Robert Blackburn
- RE: [CFCDev] Unit Test for DAO John Farrar
- Re: [CFCDev] Unit Test for DAO Brian Kotek
- RE: [CFCDev] Unit Test for DAO Jeff Chastain
- Re: [CFCDev] Unit Test for... Paul Kenney
- RE: [CFCDev] Unit Test for... Jeff Chastain
- Re: [CFCDev] Unit Test for... Brian Kotek
- RE: [CFCDev] Unit Test for... Jeff Chastain
