Pre and post test callbacks
Andy Armstrong
andy at hexten.net
Mon Nov 19 08:09:03 EST 2007
On 19 Nov 2007, at 11:11, Ovid wrote:
> 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.
+1
> 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.
Yes, I like that. The performance hit will be tiny if you don't use
the callbacks.
--
Andy Armstrong, Hexten
More information about the tapx-dev
mailing list