Practical Test-driven Development Presentation
.pdfA deeper look at Test::More
Basic Testing in Perl
--(0)> prove -Ilib t/percent_ownership.t t/percent_ownership....ok
All tests successful.
Files=1, Tests=12, 0 wallclock secs ( 0.02 cusr + 0.01 csys = 0.03 CPU)
71
Exercise One
•Using Test::More and prove, write a module that converts temperatures from Celsius to Fahrenheit.
•After the conversion starts working with Celsius to Fahrenheit, add a method to convert from Fahrenheit to Celsius.
•Now, add some testing to see how the methods work with potentially damaging cases such as fractional numbers, negative temperatures, and non-numeric input.
72
Taking a look at the TAP
Basic Testing in Perl
•What is ‘prove’ doing when it runs our tests?
•It is running our testing scripts using ‘perl’.
•Then intercepting the output.
•And finally formatting the output in a nice summarized form.
73
Taking a look at the TAP
Basic Testing in Perl
--(0)> |
perl -Ilib t/percent_ownership.t |
|
1..12 |
|
|
ok 1 - |
use PercentOwnership; |
|
ok 2 - |
PercentOwnership->can('new') |
|
ok 3 - |
The object isa PercentOwnership |
|
ok 4 - |
PercentOwnership->can(...) |
|
ok 5 - |
unit added successfully |
|
ok 6 |
- |
single unit condo |
ok 7 |
- |
The object isa PercentOwnership |
ok 8 |
- |
PercentOwnership->can(...) |
ok 9 |
- |
first unit added successfully |
ok 10 |
- second unit added successfully |
|
|||
ok |
11 |
- 50/50 |
ownership |
split for unit 101 |
|
ok |
12 |
- 50/50 |
ownership |
split for unit |
102 |
74
A deeper look at Test::More
Basic Testing in Perl
"t/percent_ownership.t"
1 use warnings;
2 use strict;
3 use Test::More qw(no_plan);
4
75
Taking a look at the TAP
Basic Testing in Perl
--(0)> |
perl -Ilib t/percent_ownership.t |
|
ok 1 - |
use PercentOwnership; |
|
ok 2 - |
PercentOwnership->can('new') |
|
ok 3 - |
The object isa PercentOwnership |
|
ok 4 - |
PercentOwnership->can(...) |
|
ok 5 - |
unit added successfully |
|
ok 6 |
- |
single unit condo |
ok 7 |
- |
The object isa PercentOwnership |
ok 8 |
- |
PercentOwnership->can(...) |
ok 9 |
- |
first unit added successfully |
ok 10 |
- second unit added successfully |
|
|||
ok |
11 |
- 50/50 |
ownership |
split for unit 101 |
|
ok |
12 |
- 50/50 |
ownership |
split for unit |
102 |
1..12
76
A deeper look at Test::More
Basic Testing in Perl
"t/percent_ownership.t"
52 |
is( |
53 |
$po->percent_ownership( unit_number => 102 ), |
54 |
51, |
55 |
'50/50 ownership split for unit 102' |
56 |
); |
77
Taking a look at the TAP
Basic Testing in Perl
--(0)> perl -Ilib t/percent_ownership.t 1..12
ok 1 - use PercentOwnership;
ok 2 - PercentOwnership->can('new') ok 3 - The object isa PercentOwnership ok 4 - PercentOwnership->can(...)
ok 5 - unit added successfully ok 6 - single unit condo
ok 7 - The object isa PercentOwnership ok 8 - PercentOwnership->can(...)
ok 9 - first unit added successfully ok 10 - second unit added successfully
ok 11 - 50/50 ownership split for unit 101 not ok 12 - 50/50 ownership split for unit 102
#Failed test '50/50 ownership split for unit 102'
#at t/percent_ownership.t line 52.
# |
got: '50' |
#expected: '51'
#Looks like you failed 1 test of 12.
78
A deeper look at Test::More
Basic Testing in Perl
"t/percent_ownership.t"
57 SKIP: {
58skip "The conditions are not right to run this test", 1;
59ok(
60 $po->something_that_requires_network_access, 61 'did a network operation'
62);
63}
79
Taking a look at the TAP
Basic Testing in Perl
--(0)> perl -Ilib t/percent_ownership.t 1..13
ok 1 - use PercentOwnership;
ok 2 - PercentOwnership->can('new') ok 3 - The object isa PercentOwnership ok 4 - PercentOwnership->can(...)
ok 5 - unit added successfully ok 6 - single unit condo
ok 7 - The object isa PercentOwnership ok 8 - PercentOwnership->can(...)
ok 9 - first unit added successfully ok 10 - second unit added successfully
ok 11 - 50/50 ownership split for unit 101 ok 12 - 50/50 ownership split for unit 102
ok 13 # skip The conditions are not right to run this test
80