in reply to Re^2: Test::MockDBI example
in thread Test::MockDBI example [SOLVED]

Why should I want to mock my DbLibTry class?

Mocking DbLibTry::get_all_songs() is what you seem to be asking for when you write $mock_dbi->set_retval( method => 'get_all_songs', ...

I just want to mock all connections to a database.

Then you should be replacing your real DBI object with the fake one, as suggested earlier, something like $dblibtry->{dbh} = $mock_dbi; - and in this case of course you shouldn't call your connect, or you'll get a real DBI object.

Replies are listed 'Best First'.
Re^4: Test::MockDBI example
by brilant_blue (Beadle) on Feb 10, 2015 at 09:13 UTC

    Yes, you are right with the replacement of real DBI object with the fake one.

    I found the Perl Practical Test-Driven Development Presentation on the Internet where it is nicely described. (Thank you Google!) The presentation is about TDD but it covers also database tests. It can be freely downloaded from here:

    http://cdn.oreillystatic.com/en/assets/1/event/12/Practical Test-driven Development Presentation.pdf

    Well, I think my problem is solved. When I'll have next problem I'll let you know about it :-)

    Thank you.