Test::A...ookbook(3)

πŸ“¦
version 0.11 Β· 2 versions
, in fedora 43

πŸŽ€ 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 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