Hi,

I'm looking for a better way to test my modules that are using DBIx::Class models by setting up mock data (in large number of tables) and then running test scripts.

So far, I've been using this code (per module):

#! /usr/bin/perl -w use strict; use Data::Dumper; BEGIN { use DBIx::RunSQL; open(FH,'>','/tmp/create.sql') or die('Could not create a file'); print FH <<EOX; CREATE TABLE `module_test_table` ( `id` int(10) NOT NULL PRIMARY KEY, `name` varchar(100) NOT NULL, `description` varchar(255) default NULL, ); INSERT INTO module_test_table VALUES (1, 'Name1', NULL); INSERT INTO module_test_table VALUES (2, 'Name2', NULL); EOX close(FH); my $dbh = DBIx::RunSQL->create( dsn => 'dbi:SQLite:dbname=:memory:', sql => '/tmp/create.sql', force => 1, #verbose => 1, ); # override the config file where database connection string is # located, instead setup database handle use Internal::Config; $Internal::Config::c->{dbh} = $dbh; $Internal::Config::c->{db_dsn} = undef; $ENV{DBIC_TRACE} = 1; } use Test::More 'no_plan'; # module using DBIx::Class model use ModuleTest; my $module_test = ModuleTest->new({ id => 1 }); is($t->id, 1, 'Value of id'); is($t->name, 'Name1', 'Value of name'); is($t->description, undef, 'Value of description');

This works fine, but I would like to use the actual DBIx::Class models to create tables and set data, and also to extract the boilerplate code to one file used by test scripts.

Thanks


In reply to in-memory database, testing modules using DBIx::Class models by stepamil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.