sub pre_test : Test(setup) {
# add objects to the database
}
sub get_objects : Tests {
# get the objects and test 'em
}
sub post_test : Test(teardown) {
# clean the database
}
####
package TestBase;
use base 'Test::Class';
INIT { Test::Class->runtests }
1;
####
package Foo;
use Test::More;
use lib '.';
use base 'TestBase';
sub setup : Tests(setup => 1) {
ok 1, 'Foo: should be called first';
}
sub some_test : Tests(1) {
ok 1, 'Foo: some test';
}
sub not_overridden : Tests(1) {
ok 1, "Let's hope this isn't dependent on Foo's setup method";
}
1;
####
package Bar;
use Test::More;
use lib '.';
use base 'Foo';
sub setup : Tests(setup => 1) {
ok 1, 'Bar: should be called second';
}
sub some_test : Tests(1) {
ok 1, 'Bar: some test';
}
1;
####
1..8
ok 1 - Bar: should be called second
ok 2 - Let's hope this isn't dependent on Foo's setup method
ok 3 - Bar: should be called second
ok 4 - Bar: some test
ok 5 - Foo: should be called first
ok 6 - Let's hope this isn't dependent on Foo's setup method
ok 7 - Foo: should be called first
ok 8 - Foo: some test
ok
All tests successful.
Files=1, Tests=8, 0 wallclock secs ( 0.11 cusr + 0.02 csys = 0.12 CPU)
####
sub setup : Tests(setup => 1) {
my $test = shift;
$test->SUPER::setup;
ok 1, 'Bar: should be called second';
}