GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::Able::Cookbook(3) User Contributed Perl Documentation Test::Able::Cookbook(3)

Test::Able::Cookbook

Dumping execution plan
 $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.
Remove superclass methods
 use Test::Able::Helpers qw( prune_super_methods );
 $t->prune_super_methods;
    

Unlike Test::Class its very easy to shed the methods from superclasses.

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 } ]
 );
    

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.

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 (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"

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.

2011-11-20 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.