|The stupid question is the question not asked|
How to do automated tests of a database centric CPAN moduleby jds17 (Pilgrim)
|on Oct 20, 2012 at 23:25 UTC||Need Help??|
jds17 has asked for the
wisdom of the Perl Monks concerning the following question:
in a few days I want to put the first version of DBIx::Table::TestDataGenerator on CPAN. One of the issues I need to solve is how to provide meaningful tests. The module will try to support as many DBMSs as possible, currently Oracle and PostgreSQL are supported, there will be more and I try to make it easily extensible to other DBMSs I have not thought of. The tests I have currently written target Oracle and PostgreSQL, and to connect to the databases the tests pick up some environment variables. In case those variables are absent, they are asked from the user running 'build test'.
So, for interactively installing and running the tests, I am fine. But this obviously does not work when CPAN testers will run the tests.
Would it be feasible to bundle an SQLite database and run the tests against it in case no other database has been specified? I cannot think of a simpler database to test against, at least the thing would need to allow constraints such as primary and foreign keys as well as uniqueness constraints. I looked at DBD::Mock, but I don't see how this could help me since SQL code is not really being run against some sort of tables and one would need to mock the expected results too, which would not be a useful testing approach.
How would you handle such tests? I am sure not to be the first person to face this issue, but I could not yet find a good enough answer, e.g. when looking up the tests of other DBIx modules.
Update: Having had few experience with SQLite, after having read some documentation for DBD::SQLite, I was pleased to see how easy it is to create an in memory database, making it unnecessary to bundle a SQLite database with the module for testing purposes.