Test2::Aggregate - Aggregate tests
use Test2::Aggregate; Test2::Aggregate::run_tests( dirs => \@test_dirs ); done_testing();
Version 0.02
Aggregates all tests specified in dirs (which can even be individual tests), to avoid forking, reloading etc that can help with performance or profiling. Test files are expected to end in .t and are run as subtests of a single aggregate test.
dirs
A bit similar but simpler in concept and execution than Test::Aggregate, which makes it more likely to work with your test suite and also with more modern Test2 bundles. It does not try to package each test which may be good or bad (e.g. redefines), depending on your requirements.
Test::Aggregate
run_tests
Test2::Aggregate::run_tests( dirs => \@dirs, # optional if lists defined lists => \@lists, # optional if dirs defined root => '/testroot/', # optional load_modules => \@modules, # optional shuffle => 1, # optional reverse => 1, # optional repeat => $no_iterations, # optional, requires Test2::Plugin::BailOnFail for < 0 slow => 1, # optional override => \%override, # optional, requires Sub::Override stats_output => $stats_output_path, # optional, requires Time::HiRes test_warnings => 1 # optional );
Runs the aggregate tests. Hash parameter specifies:
dirs (either this or lists is required)
lists
An arrayref containing directories which will be searched recursively, or even individual tests. The directories (unless shuffle or reverse are true) will be processed and tests run in order specified.
shuffle
reverse
lists (either this or dirs is required)
Arrayref of flat files from which each line will be pushed to dirs (so they have a lower precedence - note root still applies).
root
root (optional)
Specifies a root directory to prefix all dirs (and lists items) with.
load_modules (optional)
load_modules
Arrayref with modules to be loaded (with eval "use ...") at the start of the test. Useful for testing modules with special namespace requirements.
eval "use ..."
override (optional)
override
Pass Sub::Override key/values as a hashref.
Sub::Override
repeat (optional)
repeat
Number of times to repeat the test(s). If repeat is negative, the test will repeat until it fails (or produces a warning when test_warnings is also set).
test_warnings
shuffle (optional)
Random order of tests.
reverse (optional)
Reverse order of tests.
slow (optional)
slow
When true, tests will be skipped if the environment variable SKIP_SLOW is set.
SKIP_SLOW
test_warnings (optional)
Tests for warnings over all the tests. It will print an array of warnings, however if you want to see the warnings the moment they are generated (for debugging etc), then leave it disabled.
stats_output_path (optional)
stats_output_path
stats_output_path when defined specifies a path where a file with running time per test (average if multiple iterations are specified), starting with the slowest test and passing percentage gets written. On negative repeat the stats of each successful run will be written separately instead of the averages. The name of the file is caller_script-YYYYMMDD_HHmmss.txt.
caller_script-YYYYMMDD_HHmmss.txt
Not all tests can be modified to run under the aggregator, it is not intended for tests that require an isolated environment. So, for those that do not, sometimes very simple changes might needed like giving unique names to subs (or not warning for redefines, or replacing things that complain such as Test::More), restoring the environment at the end of the test etc.
Test::More
Speaking about Test::More, by replacing Test2:V0 with Test::More in the source of this module would generally work fine (except for the option repeat < 0) and not complain on Test::More-based suites, but perhaps you'd be better off starting to move to Test2.
Test2:V0
repeat < 0
The environment variable AGGREGATE_TESTS will be set while the tests are running. Example usage is a module that can only be loaded once, so you load it on the aggregated test file and then use something like this in the individual test files:
AGGREGATE_TESTS
eval 'use My::Module' unless $ENV{AGGREGATE_TESTS};
Trying to aggregate too many tests into a single one can be counter-intuitive as you would ideally want to parallelize your test suite (so a super-long test continuing after the rest are done will slow down the suite). And in general more tests will run aggregated if they are grouped so that tests that can't be aggregated together are in different groups.
Dimitrios Kechagias, <dkechag at cpan.org>
<dkechag at cpan.org>
Please report any bugs or feature requests to bug-test2-aggregate at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test2-Aggregate. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-test2-aggregate at rt.cpan.org
https://github.com/SpareRoom/Test2-Aggregate
Copyright (C) 2019, SpareRoom.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test2::Aggregate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test2::Aggregate
CPAN shell
perl -MCPAN -e shell install Test2::Aggregate
For more information on module installation, please visit the detailed CPAN module installation guide.