Test::Aggregate
Test::Aggregate is a simple, yet fantastic module that allows, you guessed it, tests to be aggregated. This turns out to be a true god send when testing large Catalyst apps.
Previously in order to run all the tests against an app I would generally have ran a stand alone server in one terminal, and then ran the tests against that stand alone instance in another, something along the lines of:
term1#> perl script/myapp_server.pl term2#> CATALYST_SERVER="http://localhost:3000" prove -Ilib t
Of course simply running prove t would run all the tests, but with the time taken to initialise the Catalyst instance being added to the start of each test, this could be hugely time consuming.
Using Test::Aggregate a very simple script can be knocked up that will run all your tests, and only actually create a single Catalyst instance.
use Test::Aggregate;
my $tests = Test::Aggregate->new( {
dirs => 'myapp/t',
} );
$tests->run;
This will load all your tests, each into their own unique package space. Meaning that only a single Perl instance is required to run all the tests and that all the required modules will only be loaded once. Both the overhead in running the entire test suite and the execution time will be drastically reduced.
Problems can occur if you are using global variables, in that they may be overwitten by the tests as they run, but of course you aren’t using them anyway… are you?
3 comments
Yes, Test::Aggregate is indeed quite awesome. The Catalyst tests itself (which take quite a while to run normally) can use it too, if you set the AGGREGATE_TESTS environment variable.
Test::Aggregate++
It made one of my test suites run 6x faster.
Irony, A blog about perl on wordpress, written in php, I thought you guys hated teh php :p
Have a good weekend mate!
Leave a Comment