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


in reply to Setting up database connection in tests

Certainly, since the testing frameworks are Perl programs, you should in those tests use a single module whose purpose is to establish the database-connection and to return the handles needed by all tests.   Once the module has been constructed and verified, it does not itself need to be the subject of a test.

As previously suggested, it can also be a “mock-up” which is known to consistently produce the same test-data.   You can even go one step further by designing a subroutine that returns a “letter-bomb $dbh.”   This returns an object that has the same necessary-for-your-app methods as a real database-handle, but which methods are contrived in some way to “blow up,” thereby predictably and consistently simulating error conditions without actually having to jimmy-up code that actually throws the desired error for any genuine reasons.