Test::SQLite - SQLite setup/teardown for tests
version 0.0409
use DBI; use Test::SQLite; # An empty test db: my $sqlite = Test::SQLite->new; my $dbh = $sqlite->dbh; # Fiddle with the test database... $dbh->disconnect; # Use an in-memory test db: $sqlite = Test::SQLite->new(memory => 1); # Copy a database file to the test db: $sqlite = Test::SQLite->new(database => '/some/where/database.db'); # Use a schema file to create the test db: $sqlite = Test::SQLite->new( schema => '/some/where/schema.sql', db_attrs => { RaiseError => 1, AutoCommit => 0 }, ); # Explicitly use the dsn and db_attrs to connect: $dbh = DBI->connect($sqlite->dsn, '', '', $sqlite->db_attrs); # Fiddle with the test database... $dbh->commit; $dbh->disconnect;
Test::SQLite is inspired by Test::PostgreSQL and Test::mysqld, and creates a temporary sqlite database to use in tests.
Test::SQLite
This module will also return the database dbh handle, dsn connection string, and db_attrs connection attributes.
The existing database to copy to create a new test database.
Boolean indicating that a database file was provided to the constructor.
The SQL schema with which to create a test database.
* The SQL parsing done by this module does not handle triggers.
Boolean indicating that a schema file was provided to the constructor.
Create a test database in memory.
Boolean indicating that memory was provided to the constructor.
DBI connection attributes.
Default: { RaiseError => 1, AutoCommit => 1 }
The database connection string. This is a computed attribute and an argument given to the constructor will be ignored.
A connected database handle based on the dsn and db_attrs. This is a computed attribute and an argument given to the constructor will be ignored.
$sqlite = Test::SQLite->new; $sqlite = Test::SQLite->new(%arguments);
Create a new Test::SQLite object.
The t/01-methods.t file in this distribution.
The eg/dbic.t example test in this distribution.
DBI
File::Copy
File::Temp
Moo
Kaitlyn Parkhurst (SYMKAT) <symkat@symkat.com>
Gene Boggs <gene@cpan.org>
This software is copyright (c) 2020 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test::SQLite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::SQLite
CPAN shell
perl -MCPAN -e shell install Test::SQLite
For more information on module installation, please visit the detailed CPAN module installation guide.