I having some issues writing test scripts for CGI-Application-Plugin-PageLookup. The Makefile.PL lists DBI as a dependency but I do not state a dependency on any particular driver because of course it should not depend on any particular driver (or at least I would hope). In production I use DBD::mysql but my test scripts use DBD::SQLite. The test scripts are now generally failing because many test machines do not have DBD::SQLite installed. In fact I have failed to install DBD::SQLite on my production machine. So now I am looking for an alternative. mysql will not do because many machines (including my production machine) do not permit creating databases from scripts (or even via phpmyadmin). From the documentation I cannot see how one would use DBD::Sponge which is a shame since that ships with DBI itself. DBD::CSV looks promising but happens to be not installed on my production machine. It happens that I wrote a similar query to this sometime back writing DBI applications offline so I am reviewing that.

First question: Why would DBI be installed on a test machine but not a sensible driver? I cannot see a sensible answer to that even for test machines. The failing machines seem to support the following drivers: DBM, ExampleP, File, Gofer, Mock, Proxy, Sponge.

What are my options? I can think of the following:

  1. State that DBD::SQLite is a dependency. This seems to me a bad solution for simply being untrue.
  2. Put guards in my test scripts so that any test script depending on DBD::SQLite will simply skip. This seems to be the cleanest workable solution but sort of invalidates the testing for a lot of people.
  3. Several modules come up in the previous thread that I cannot see working: Mock, SQLite::Amalgamation. Could someone who has successfully used these please elaborate.
  4. DBD::Sponge and DBD:DBM look like they might work and come with DBI, but I am not sure.
  5. Test::MockDBI looks like it should work but I find the idea of trying to work out what SQL I am going to run really offputting. Specifically it is wrong headed. The whole reason I use a database is because the same data gets used multiple times and the SQL language allows me to state it once and query it from multiple angles. TestMockDBI seems to undermine that.
  6. I have had the idea of writing a DBD::TestVirtual driver. In setting this up you would state a list of real drivers in order of preference, and also hooks for creating, populating and destroying the test databases dynamically. The driver would try each of these in turn until it found one that worked and return a handle to that. Sounds cool until I think using it may be more hassle than Test::MockDBI.

I have the strong feeling I am going to regret posting this because somewhere up there I have answered my own question. At the very least it would be nice to know if other people have found similar issues and how they solved them.


In reply to How to write test scripts depending on DBI by SilasTheMonk

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.