water has asked for the wisdom of the Perl Monks concerning the following question:
Samples have dimensions like size, color, temp, volume, melting point; each dimension has a fixed number of attributes (for example, size --> small, medium, large; temp --> low, high, etc).
I have code like this:
Now, the dimensions and samples are stored by dim_id and att_id in the sample_info table, which are foreign keys into the dimension and attribute tables (these contain full information on each dim and att).# psuedo-code foreach $sample foreach $dim determine attribute for sample for dim store (sample_id, dim_id, att_id) in database } }
Also, sometimes the dim and att need to be created on the fly -- long story why, but true. In this case, given a sample should fall into dimension "woozle" with attribute "foozle", new rows must be cut in dimension and attribute before we can store (sample_id, dim_id, att_id) in database.
Final detail: all db access is thru class::dbi.
I'm looking for advice.
I don't want to test using bogus samples going into the database; I don't want to delete them and don't want them there.
This leads me to heavy us of Test::Class, Test::MockObject, and Sub::Override.
Heavy heavy use.
I've had trouble using Override on CDBI autocreated methods like 'search' -- thus, I've needed to push that functionality into methods to be able to override (eg mock) those.
Test::Class saves me a great deal of time, because the painful set-up stuff to do testing (200+ LOC, at this point, and not simple lines) can be recycled.
But this is still a pain.
Any advice, wise monks, on testing a CDBI app using mocking, besides placing just about every DB call (search / update / create) in its own micro-method, so it can tested and then overriden when used to test a parent method?
Too much mock code --
2005-09-29 Retitled by g0n, as per Monastery guidelines
Original title: 'Eaiser Mocking?'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Easier Mocking?
by xdg (Monsignor) on Sep 27, 2005 at 11:33 UTC | |
|
Re: Easier Mocking?
by Anonymous Monk on Sep 27, 2005 at 11:34 UTC | |
|
Re: Easier Mocking?
by dragonchild (Archbishop) on Sep 27, 2005 at 13:21 UTC | |
by vampirechicken9 (Initiate) on Sep 27, 2005 at 15:11 UTC |