[Pdx-pm] interesting testing hole thats been dug

Wil Cooley wcooley at nakedape.cc
Wed Jan 3 20:32:42 PST 2007

On Tue, 2007-01-02 at 16:36 -0800, benh wrote:
> A co-worker and I are wondering how/what the best way around this is?
> we have a module that cans up all our DB connections... but when I
> want to test it should be a mocDB object... so we now have a DBTest
> that builds out the mocDB stuffies. But the issue now is that to get
> all the existing scripts to use DBTest for our tests.
> Is there a clean way to intercept DB calls? is there some kinda bubble
> that we can toss the scripts in to and then any call out gets
> redirected? Our inital though was to just set an env var and then when
> the script would run then it would pick the right object, but that
> requires selecting a use statement (ie if($ENV{test}){use DBTest; }
> else {use DBHost;} ) alas that doesn't work.... any other ideas?

It may not be the best or right way to do it, but I just put in a
backdoor in my constructor to allow me to pass in an object of the
expected type (and documented it as an unsupported, test-only sort of
feature).  The module in question is basically a facade around Net::FTP:


(My constructor is private and called "_new()".)

Then I create Test::MockObject objects for my tests:


Wil Cooley <wcooley at nakedape.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/pdx-pm-list/attachments/20070103/4b9ed0b1/attachment.bin 

More information about the Pdx-pm-list mailing list