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

Hi.

Newbie testing question:

I'd like put some sql assertions in my test suite -- basically, query

select blah from blah blah where blah blah blah
should return zero rows, or N rows, or whatever. Not seeing anything thing in the Test:: family with this feature (did I miss something?), I planned to write my own Test::Sql module, extending Test::More, so I could write
use strict; use Test::More tests=>19; use Test::Sql; ... ... no_rows(q(select blah from blah blah where blah blah blah)), 'correctl +y empty blah query')) ... ...
. The no_rows subroutine would grab the right DBI handle, query, retrieve rows, "OK" if no rows, and fail to displayu a rowcount and the first few rows returned if not zero rows.

How do I extend Test::More so that the numbering still works? Do I emit my own "ok" or "nok", and how do I maintaining numbering? Is there a good test building faq somewhere I missed?

Many THanks

-water-

Replies are listed 'Best First'.
Re: Extending Test::More
by lachoy (Parson) on May 19, 2004 at 15:40 UTC
    If you want to interact with a database, Test::DatabaseRow looks like it fits the bill. If you want to pretend to interact with a database, check out DBD::Mock.

    Chris
    M-x auto-bs-mode

Re: Extending Test::More
by chromatic (Archbishop) on May 19, 2004 at 16:40 UTC
Re: Extending Test::More
by pg (Canon) on May 20, 2004 at 04:42 UTC

    A comment on your sql statement. If what you are interested in is the number of rows being returned, then just go:

    select count(*) from blah

    As your "select blah from" send sback data that you are not even interested. Especailly if you are accessing database over network, there would be a big waste of time and resource.