Test::Able::Cookbook
$ENV{ 'TEST_VERBOSE' } = 1; $t->meta->dry_run( 1 ); $t->run_tests;
Does everything but call the test (startup/setup/test/teardown/shutdown) methods and validate method plans. And part of "everything" is logging the execution plan with $t->meta->log.
Its not recommended to do any of this while a test run is in progress. The BUILD method in the test class is the best place.
use Test::Able::Helpers qw( prune_super_methods ); $t->prune_super_methods;
Unlike Test::Class its very easy to shed the methods from superclasses.
my @methods = sort { $a->name cmp $b->name } $t->meta->get_all_methods; $t->meta->startup_methods( [ @methods[ 17 .. 20 ] ] ); $t->meta->setup_methods( [ @methods[ 25 .. 28 ] ] ); $t->meta->test_methods( [ @methods[ 30, 32 ] ] ); $t->meta->teardown_methods( [ @methods[ 13 .. 16 ] ] ); $t->meta->shutdown_methods( [ @methods[ 21 .. 24 ] ] );
use Test::Able::Helpers qw( shuffle_methods ); for ( 1 .. 10 ) { $t->shuffle_methods; $t->run_tests; }
Simple xUnit purity test.
$t->meta->test_methods( [ grep { $_->name !~ /bar/; } @{ $t->meta->test_methods } ] );
test plan => "no_plan", new_test_method => sub { $_[ 0 ]->meta->current_method->plan( 7 ); ok( 1 ) for 1 .. 7; };
This will force the whole plan to be recalculated.
use Test::Able::Helpers qw( get_loop_plan ); test do_setup => 0, do_teardown => 0, test_on_x_and_y_and_z => sub { my ( $self, ) = @_; my @x = qw( 1 2 3 ); my @y = qw( a b c ); my @z = qw( foo bar baz ); $self->meta->current_method->plan( $self->get_loop_plan( 'test_bar1', @x * @y * @x, ), ); for my $x ( @x ) { for my $y ( @y ) { for my $z ( @z ) { $self->meta->run_methods( 'setup' ); $self->{ 'args' } = { x => $x, y => $y, z => $z, }; $self->test_bar1; $self->meta->run_methods( 'teardown' ); } } } return; };
Since we're running the setup and teardown method lists explicitly in the loop it would be nice to have the option of not running them implicitly (the normal behavior - see "run_methods" in Test::Able::Role::Meta::Class ). Setting do_setup the do_teardown above to false is an easy way to accomplish just that.
Justin DeVuyst, justin@devuyst.com
justin@devuyst.com
Copyright 2009 by Justin DeVuyst.
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::Able, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Able
CPAN shell
perl -MCPAN -e shell install Test::Able
For more information on module installation, please visit the detailed CPAN module installation guide.