1Test::Able::Cookbook(3)User Contributed Perl DocumentatioTnest::Able::Cookbook(3)
2
3
4
6 Test::Able::Cookbook
7
9 Basics
10 Dumping execution plan
11 $ENV{ 'TEST_VERBOSE' } = 1;
12 $t->meta->dry_run( 1 );
13 $t->run_tests;
14
15 Does everything but call the test
16 (startup/setup/test/teardown/shutdown) methods and validate method
17 plans. And part of "everything" is logging the execution plan with
18 $t->meta->log.
19
20 Altering Method Lists
21 Its not recommended to do any of this while a test run is in progress.
22 The BUILD method in the test class is the best place.
23
24 Remove superclass methods
25 use Test::Able::Helpers qw( prune_super_methods );
26 $t->prune_super_methods;
27
28 Unlike Test::Class its very easy to shed the methods from
29 superclasses.
30
31 Explicit set
32 my @meth = sort { $a->name cmp $b->name } $t->meta->get_all_methods;
33 $t->meta->startup_methods( [ grep { $_->name =~ /^shutdown_/ } @meth ] );
34 $t->meta->setup_methods( [ grep { $_->name =~ /^teardown_/ } @meth ] );
35 $t->meta->test_methods( [ grep { $_->name =~ /^test_bar[14]/ } @meth ] );
36 $t->meta->teardown_methods( [ grep { $_->name =~ /^setup_/ } @meth ] );
37 $t->meta->shutdown_methods( [ grep { $_->name =~ /^startup_/ } @meth ] );
38
39 Ordering
40 use Test::Able::Helpers qw( shuffle_methods );
41 for ( 1 .. 10 ) {
42 $t->shuffle_methods;
43 $t->run_tests;
44 }
45
46 Simple xUnit purity test.
47
48 Filtering
49 $t->meta->test_methods(
50 [ grep { $_->name !~ /bar/; } @{ $t->meta->test_methods } ]
51 );
52
53 Test Planning
54 Setting method plan during test run
55 test plan => "no_plan", new_test_method => sub {
56 $_[ 0 ]->meta->current_method->plan( 7 );
57 ok( 1 ) for 1 .. 7;
58 };
59
60 This will force the whole plan to be recalculated.
61
62 Advanced
63 Explicit setup & teardown for "Loop-Driven testing"
64 use Test::Able::Helpers qw( get_loop_plan );
65
66 test do_setup => 0, do_teardown => 0, test_on_x_and_y_and_z => sub {
67 my ( $self, ) = @_;
68
69 my @x = qw( 1 2 3 );
70 my @y = qw( a b c );
71 my @z = qw( foo bar baz );
72
73 $self->meta->current_method->plan(
74 $self->get_loop_plan( 'test_bar1', @x * @y * @x, ),
75 );
76
77 for my $x ( @x ) {
78 for my $y ( @y ) {
79 for my $z ( @z ) {
80 $self->meta->run_methods( 'setup' );
81 $self->{ 'args' } = { x => $x, y => $y, z => $z, };
82 $self->test_bar1;
83 $self->meta->run_methods( 'teardown' );
84 }
85 }
86 }
87
88 return;
89 };
90
91 Since we're running the setup and teardown method lists explicitly
92 in the loop it would be nice to have the option of not running them
93 implicitly (the normal behavior - see "run_methods" in
94 Test::Able::Role::Meta::Class ). Setting do_setup the do_teardown
95 above to false is an easy way to accomplish just that.
96
98 Justin DeVuyst, "justin@devuyst.com"
99
101 Copyright 2009 by Justin DeVuyst.
102
103 This library is free software, you can redistribute it and/or modify it
104 under the same terms as Perl itself.
105
106
107
108perl v5.28.1 2011-11-20 Test::Able::Cookbook(3)