I've used DBD::Mock, but not DBI::Mock. Using a mock database allows much better control over database failure handling than you can generally achieve with a real database. So they are the tools to turn to when you want to see that your code handles an insertion failure or a lost connection, or other database server side issues that your code need to manage.

Using a real database is a better tool for testing your business logic. If your code is fairly database agnostic you can even use things like DBD::CSV to wrap text files containing the database data. Simple diffs against reference versions of the file let you check that the database is updated as expected. Dealing with text files also has the advantage that diffs between version in your revision control system make sense.

Test::Mock::Class works well to wrap a shim around other modules so the tested code doesn't need to be switched to "Test mode".

Writing the tests can be a lot of work. Test driven development makes it easier to incorporate test development into the general development process and makes it harder to miss important areas of testing.

Perl is the programming world's equivalent of English

In reply to Re^3: Mock Test Cases by GrandFather
in thread Mock Test Cases by arora.ajay06

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.