http://www.perlmonks.org?node_id=424482


in reply to Testing a DBI module

Maybe DBD::Mock can help you. It does not connect to any real database, but just traces all the SQL you issue, so that you can later check if that is what you wanted.

Maybe you want to have a look at DBD::SQLite. While it does not exist everywhere, it is easy to install anywhere because it contains its own DBMS.

You could have some tests that only run if DBD::SQLite is present (using a temporary file for your test DB).

You can also have the user set the DBI connect string via an environment variable if he wants to run the tests against his real database. These tests will be skipped in automated testing, but at least they can run them after reading your README if they want.

Replies are listed 'Best First'.
Re^2: Testing a DBI module
by grinder (Bishop) on Jan 24, 2005 at 11:16 UTC
    It does not connect to any real database

    Excellent advice. This reminds me that it's probably worth raising the awareness of barbie's rant on DBI testing: Trojan Perl Distributions. If you haven't read that thread, then one should take a look at it now.

    - another intruder with the mooring in the heart of the Perl

Re^2: Testing a DBI module
by dragonchild (Archbishop) on Jan 24, 2005 at 14:33 UTC
    While it does not exist everywhere, it is easy to install anywhere because it contains its own DBMS.

    Assuming, of course, you have the same C compiler that was used to compile your version of Perl and you're on one of the systems that SQLite will work on. Remember - Perl works on over 200 different OSes. I'm pretty sure SQLite doesn't have the same claim. DBD::Mock is a much better choice.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.