Test::A...ookbook(3)
π NAME π
Test::Able::Cookbook β bestie, this is the recipe book. π It lives in the User Contributed Perl Documentation section, and it's literally a bunch of copy-paste-able tricks for driving Test::Able around. No cap.
πΈ RECIPES πΈ
β¨ Basics β¨
π Dumping execution plan
$ENV{ 'TEST_VERBOSE' } = 1;
$t->meta->dry_run( 1 );
$t->run_tests;
Okay so this does everything β except it does not call the test methods (startup/setup/test/teardown/shutdown) and it does not validate method plans. And part of that "everything" is logging the execution plan with $t->meta->log. So you get the whole itinerary without actually going on the trip. π¦
π₯ Altering Method Lists π₯
ngl bestie, it is 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 for it. Periodt.
π Remove superclass methods
use Test::Able::Helpers qw( prune_super_methods );
$t->prune_super_methods;
Unlike Test::Class, it's so easy to shed the methods from superclasses. Iconic honestly. π
π§ Explicit set
my @meth = sort { $a->name cmp $b->name } $t->meta->get_all_methods;
$t->meta->startup_methods( [ grep { $_->name =~ /^shutdown_/ } @meth ] );
$t->meta->setup_methods( [ grep { $_->name =~ /^teardown_/ } @meth ] );
$t->meta->test_methods( [ grep { $_->name =~ /^test_bar[14]/ } @meth ] );
$t->meta->teardown_methods( [ grep { $_->name =~ /^setup_/ } @meth ] );
$t->meta->shutdown_methods( [ grep { $_->name =~ /^startup_/ } @meth ] );
π Ordering
use Test::Able::Helpers qw( shuffle_methods );
for ( 1 .. 10 ) {
$t->shuffle_methods;
$t->run_tests;
}
Simple xUnit purity test. β¨
π¦ Filtering
$t->meta->test_methods(
[ grep { $_->name !~ /bar/; } @{ $t->meta->test_methods } ]
);
π Test Planning π
β Setting method plan during test run
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. The way it just recalculates the entire planβ¦ π iconic.
π Advanced π
π₯ Explicit setup & teardown for "Loop-Driven testing"
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 β that's the normal behavior, see run_methods in Test::Able::Role::Meta::Class. Setting do_setup and do_teardown above to false is an easy way to accomplish just that. π«Ά
π AUTHOR π
Justin DeVuyst, justin@devuyst.com
π COPYRIGHT AND LICENSE π
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.
and that's the whole cookbook, bestie!! π¦β¨ this lil page rode in on perl v5.42.0, dated 2025-07-25, and its header says Test::A...ookbook(3) β go forth and test slayfully π
πΈ
π¦ where this page comes from
- fedora 43: perl-Test-Able 0.11-41.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms