Pre and post test callbacks
Ovid
publiustemp-tapx at yahoo.com
Mon Nov 19 06:11:26 EST 2007
Hi all,
In TAP::Parser, we have a runtests method:
sub runtests {
my ( $self, @tests ) = @_;
my $aggregate = TAP::Parser::Aggregator->new;
$self->_make_callback( 'before_runtests', $aggregate );
$self->aggregate_tests( $aggregate, @tests );
$self->formatter->summary($aggregate);
$self->_make_callback( 'after_runtests', $aggregate );
return $aggregate;
}
Note that we have 'before_runtests' and 'after_runtests' callbacks. Those are run before and after the test suite. We could also use 'before_test' and 'after_test' callbacks which run before and after each test program. This brings us much closer to the startup/shutdown, setup/teardown model of Test::Class.
Of course, this might slow things down a tad, but here's a killer use case:
1. Before the tests, setup your test database, run all of your tests, tear down the test database.
2. Some tests fail and you think it's bad data persisting in your test database.
3. You change 'before_runtests' to 'before_test' and have the database setup and teardown before and after every test program.
When #3 hits, things will run a lot slower (for us, it went from 22 minutes to over an hour), but the isolation can expose lots of bugs.
Comments?
Cheers,
Ovid
--
Buy the book - http://www.oreilly.com/catalog/perlhks/
Perl and CGI - http://users.easystreet.com/ovid/cgi_course/
Personal blog - http://publius-ovidius.livejournal.com/
Tech blog - http://use.perl.org/~Ovid/journal/
More information about the tapx-dev
mailing list