Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Testing a DBI module

by BrentDax (Hermit)
on Jan 24, 2005 at 01:37 UTC ( [id://424476]=perlquestion: print w/replies, xml ) Need Help??

BrentDax has asked for the wisdom of the Perl Monks concerning the following question:

I'm currently working on a DBIx module. I'm trying to write a decent test suite for it, but running into a fundamental problem: it's hard to find a good DBD that'll exist everywhere and support enough to test my module.

For testing, my module needs to be able to SELECT, INSERT, and DELETE in a three-column table. DBD::DBM only supports two columns, and DBD::Sponge would (as far as I can tell) require me to change my module's code, so neither is workable; DBI doesn't ship with any other DBDs built-in.

How should a DBI-related module be tested?

--Brent Dax
There is no sig.

Replies are listed 'Best First'.
Re: Testing a DBI module
by Thilosophy (Curate) on Jan 24, 2005 at 02:29 UTC
    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.

      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

      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.

Re: Testing a DBI module
by borisz (Canon) on Jan 24, 2005 at 02:21 UTC
Re: Testing a DBI module
by jZed (Prior) on Jan 24, 2005 at 06:22 UTC
    DBD::DBM can accomodate any number of columns as long as MLDBM is available. MLDBM is an easy install on all platforms.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://424476]
Approved by sgifford
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-06-15 02:27 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.