Class::PObject::Test - Base test framework for Class::PObject drivers
package Class::PObject::Test::MyTest; require Class::PObject::Test; @ISA = ('Class::PObject::Test'); sub run { my $self = shift; my $driver = $self->{driver}; my $datasource = $self->{datasource}; # perform your tests using $driver and $datasource }
Class::PObject::Test is a base testing framework for Class::PObject drivers.
Class::PObject::Test is used as a base class by test libraries, and provides two methods, new() and run(). Subclasses of Class::PObject::Test are expected to override run().
new()
run()
Same sets of tests must be performed for every single driver available to ensure all the drivers are compatible. That's why, instead of putting redundant chunks of codes in multiple t/*.t files, we created a library, which can run same tests for different drivers.
For example, to run some basic/core tests on file driver, we do:
file
# t/01basic_file.t use Class::PObject::Test::Basic; $t = new Class::PObject::Test::Basic('file', './data'); $t->run()
To run these same set of tests for mysql driver, for example, we can do:
# t/02basic_mysql.t use Class::PObject::Test::Basic; $t = new Class::PObject::Test::Basic('mysql', {Handle=>$dbh}); $t->run()
and so on.
This will ensure that same exact tests are run for every driver.
new($driver, $datasource) - constructor method. Accepts two arguments, $driver and $datasource. You can access these object attributes from within run() to generate pobjects for testing purposes.
new($driver, $datasource)
run() - runs the tests. You can use Test::More - testing library for running the tests. A very simple test can look like:
sub run { my $self = shift; pobject ClassName => { columns => ['id', 'a', 'b', 'c'], driver => $self->{driver}, datasource => $self->{datasource} }; ok(1); my $obj = ClassName->new(); ok($obj); $obj->a('A'); $obj->b('B'); ok($obj->save) }
If you want to write a special test library, you are expected to do a little more than that, because Class::PObject::Test::Basic already performs most of the Class::PObject driver functionality.
Class::PObject::Test::Basic
For author and copyright information refer to Class::PObject's online manual.
To install Class::PObject, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::PObject
CPAN shell
perl -MCPAN -e shell install Class::PObject
For more information on module installation, please visit the detailed CPAN module installation guide.