Practical Test-driven Development Presentation
.pdfPorting our tests to use Test::Class
Object Oriented Test Frameworks
"t/PercentOwnership.pm"
1 |
package TestPercentOwnership; |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
use base qw(Test::Class); |
6 |
use Test::More; |
7 |
|
8 |
__PACKAGE__->runtests unless caller; |
9 |
|
10 |
sub my_test : Test { |
11 |
pass; |
12 |
} |
13 |
|
14 |
1; |
91
Porting our tests to use Test::Class
Basic Testing in Perl
--(0)> prove -Ilib t/TestPercentOwnership.pm t/TestPercentOwnership....ok
All tests successful.
Files=1, Tests=1, 0 wallclock secs ( 0.10 cusr + 0.03 csys = 0.13 CPU)
92
Porting our tests to use Test::Class
Basic Testing in Perl
"t/PercentOwnership.pm"
1 package TestPercentOwnership;
2
3 use warnings;
4 use strict;
5 use base qw(Test::Class);
6 use Test::More;
7
8 __PACKAGE__->runtests unless caller;
9
10 sub startup_test : Test( startup => 2 ) { 11 use_ok( 'PercentOwnership' );
12 can_ok( 'PercentOwnership', 'new' );
13 }
14
15 1;
93
Porting our tests to use Test::Class
Basic Testing in Perl
t/TestPercentOwnership....ok All tests successful.
Files=1, Tests=2, 1 wallclock secs ( 0.11 cusr + 0.03 csys = 0.14 CPU)
94
Porting our tests to use Test::Class
Basic Testing in Perl
"t/PercentOwnership.pm"
15 sub single_unit : Test(4) {
16my ($self) = @_;
17my $po = PercentOwnership->new();
18isa_ok( $po, 'PercentOwnership' );
19can_ok( 'PercentOwnership', qw( add_unit percent_ownership ) );
21 |
ok( |
|
22 |
$po->add_unit( |
|
23 |
unit_number |
=> 101, |
24 |
square_footage => 450, |
|
25 |
floor |
=> 1, |
26 |
), ‘added single unit’ |
|
27 |
); |
|
28 |
|
|
29 |
is( $po->percent_ownership( unit_number => 101 ), 100, |
|
30 |
'single unit condo' ); |
|
31 |
} |
|
95
Porting our tests to use Test::Class
Basic Testing in Perl
--(0)> prove -Ilib t/TestPercentOwnership.pm t/TestPercentOwnership....ok
All tests successful.
Files=1, Tests=6, 1 wallclock secs ( 0.04 cusr + 0.02 csys = 0.06 CPU)
96
Porting our tests to use Test::Class
Basic Testing in Perl
"t/PercentOwnership.pm"
33 sub two_units : Test(6) {
34my ($self) = @_;
35my $po = PercentOwnership->new();
36isa_ok( $po, 'PercentOwnership' );
37can_ok( 'PercentOwnership', qw( add_unit percent_ownership ) );
97
Porting our tests to use Test::Class
Basic Testing in Perl
"t/PercentOwnership.pm"
39 |
ok( |
|
40 |
$po->add_unit( |
|
41 |
unit_number |
=> 101, |
42 |
square_footage |
=> 450, |
43 |
floor |
=> 1, |
44 |
), ‘added first unit’ |
|
45 |
); |
|
46 |
|
|
47 |
ok( |
|
48 |
$po->add_unit( |
|
49 |
unit_number |
=> 102, |
50 |
square_footage |
=> 450, |
51 |
floor |
=> 1, |
52 |
), ‘added second unit’ |
|
53 |
); |
|
98
Porting our tests to use Test::Class
Basic Testing in Perl
"t/PercentOwnership.pm"
54 |
|
|
55 |
is( $po->percent_ownership( unit_number => 101 ), 50, |
|
56 |
'unit 101 |
got the correct percentage' ); |
57 |
|
|
58 |
is( $po->percent_ownership( unit_number => 102 ), 50, |
|
59 |
'unit 102 |
got the correct percentage' ); |
60 |
} |
|
99
Porting our tests to use Test::Class
Basic Testing in Perl
--(0)> prove -Ilib t/TestPercentOwnership.pm t/TestPercentOwnership....ok
All tests successful.
Files=1, Tests=12, 0 wallclock secs ( 0.04 cusr + 0.02 csys = 0.06 CPU)
100