Problem Background

I have a piece of an application that stores information about samples in a database.

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:

# psuedo-code foreach $sample foreach $dim determine attribute for sample for dim store (sample_id, dim_id, att_id) in database } }
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).

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.

Problem Asked

This part of the app is a monster to test. It is soooo tightly coupled with the database it hurts.

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 --

water

2005-09-29 Retitled by g0n, as per Monastery guidelines
Original title: 'Eaiser Mocking?'


In reply to Easier Mocking? by water

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.