Test::DataDriven - when Test::Base is not enough
In the test module:
# t/lib/MyTest.pm package MyTest; use Test::DataDriven::Plugin -base; __PACKAGE__->register; my $time; my $result; sub check_before : Begin(add1) { my( $block, $section_name, @data ) = @_; $time = time(); } sub do_that : Run(add1) { my( $block, $section_name, @data ) = @_; $result = add_1( $data[0] ); } sub check_after : End(result) { my( $block, $section_name, @data ) = @_; is( $result, $data[0] ); ok( time() - $time < 1 ); # check side effects }
In the test file:
use MyTest; use Test::More tests => 4; Test::DataDriven->run; __END__ === Test 1 --- add1 chomp 3 --- result 4 === Test 1 --- add1 chomp 7 --- result 8
Test::Base is great for writing data driven tests, but sometimes you need to test things that cannot be easily expressed using the filter-and-compare-output approach.
Test::Base
Test::DataDriven builds upon Test::Base adding the ability to declare actions to be run for each section of each test block. In particular, the processing of each block is divided in three phases: "begin", "run" and "end". The "begin" phase can be used to assess or establish the preconditions for the test. The "run" phase is used to perform some actions. The "end" phase can be used to check the side effects of the "run" phase.
Test::DataDriven
Test::DataDriven->register ( plugin => $plugin, tag => 'section_name', ); Test::DataDriven->register ( plugin => $plugin, tag_re => qr/match/, );
Registers a plugin whose begin, run and end methods will be called for each section whose name equals the one specified with 'tag' or matches the regular expression specified with 'tag_re'. At least one of 'tag' or 'tag_re' must be present.
begin
run
end
$plugin can be either a class or object reference.
$plugin
Test::DataDriven->run;
Iterates over the Test::Base blocks calling the plugins that match the block sections.
Test::DataDriven->stop_run;
Stop the tests being run.
Needs more documentation and examples.
Mattia Barbon <mbarbon@cpan.org>
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::DataDriven, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::DataDriven
CPAN shell
perl -MCPAN -e shell install Test::DataDriven
For more information on module installation, please visit the detailed CPAN module installation guide.