Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot


by water (Deacon)
on Jul 24, 2005 at 19:40 UTC ( #477605=perlmeditation: print w/replies, xml ) Need Help??

Sadly it is beyond my current capabilities to write and then CPAN it for the community, but boy, a Test::Mock::Class::DBI package (along the the lines of Test::Mock::DBI) would be a wonderful thing.

An idle suggestion!



Replies are listed 'Best First'.
Re: Test::Mock::Class::DBI
by Corion (Patriarch) on Jul 24, 2005 at 20:24 UTC

    What makes a Class::DBI object different from any other object? You can mock both with Test::MockObject

      There's lots of magic in CDBI, such as stringification to the primary key (overloading stringification doesn't quite work right in Test::MockObject, test case and bug submitted), lazy inflation, etc.

      While a C:DBI object is indeed just an object, mocking one 'by hand' via T:MO isn't simple.

      My two cents.

Re: Test::Mock::Class::DBI
by webfiend (Vicar) on Jul 25, 2005 at 05:02 UTC

    What about the article on about Test::MockDBI? Test::MockDBI sounds fairly close to what you were looking for, although maybe not exactly it.

Re: Test::Mock::Class::DBI
by Molt (Chaplain) on Jul 25, 2005 at 08:52 UTC

    With Class::DBI being fairly simple to use would it be possible to do what you're intending by mocking the database with DBD::SQLite?

    I appreciate that it keeps the Class::DBI layer intact, which is not always what you need, but I feel this achieves most testing requirements of these systems with minimal pain. mocking the database with DBD::SQLite?
      Like with DBD::Mock?


      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        Ironically enough, no, not like DBD::Mock. DBD Mock is a mock driver, not a mock database. Very big difference.

        It's DBD::Mock's stated intention to make sure the right SQL is executed and the parameters bind to it in the right place. It really doesn't care whether the SQL does what's meant of it or not, or infact whether it works or not.

        For me when I'm testing Class::DBI based classes I really don't care what SQL is actually being run, provided it does what I want in a reasonable amount of time. What I am concerned with is when I say 'Give me all the users registered after the 10th of October' that I do get the test users I purposefully created which match the criteria.

        The approach I advocate (..and try and use whenever possible, I appreciate it doesn't fit every task) is to have a SQLite-based test database, which I can rebuild quickly before each test. This way I can check things such as 'Can I add a user, and then pull them back out?', 'Can I delete all users, and then get a zero user count?', and 'If I try and add a user which doesn't match the database schema (Duplicate ID, or so on) do I get a reasonable error?'.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2023-06-03 07:21 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (8 votes). Check out past polls.