Reputation: 603
I'm looking for some ideas or techniques to write tests against code that uses an EasyDBI session
for accessing data in mysql
. I don't want the EasyDBI session
to be aware of being tested, so I was hoping to find a way to mock a DSN
or something like that. But, It's not clear to me how I might do that.
Anyone had/solved this problem before?
Upvotes: 2
Views: 87
Reputation: 603
I ended up using DBD:Mock which is pretty nice. When I set up my easy dbi component I used DBD:Mock: as the dsn. Then in the options I passed the result sets I wanted to return.
my @result_set = (list of stuff);
my $eDBI = POE::Component::EasyDBI->spawn(
alias => 'eDBI',
dsn => "DBI:Mock:",
username => "",
password => "",
options => {
AutoCommit => 0,
mock_add_resultset => \@result_set,
},
no_connect_failures => 1,
reconnect_wait => 2,
max_retries => 5,
connect_error => [ $alias, "dbi_failure", 5 ],
connected => [ $alias, "dbi_connected" ],
);
Upvotes: 2
Reputation:
Maybe Test::Database::Tutorial
/ Test::Database
this is what you need. Or you create the test database from your __DATA__
with :cache:
Upvotes: 0