This document discusses different types and levels of software testing including unit testing, integration testing, and acceptance testing. It provides examples of using various Perl testing modules like Test::More, Test::WWW::Mechanize, and Devel::Cover. Key points covered include black box vs white box testing, using mock objects and stubs, and testing on different platforms and environments.
24. use strict;
use warnings;
use Test::More;
use Test::WWW:::Mechanize;
my $data = {
name => 'MyFoo',
description => 'MyFoo é uma...',
};
my $mech = Test::WWW::Mechanize->new;
$mech->get_ok('/foo');
$mech->submit_form_ok({
with_fields => $data,
button => 'submit',
}, 'form submit...');
$mech->content_contains($data->{$_})
for qw/name description/;
# ...
done_testing;
Tuesday, October 08, 2013
27. use strict;
use warnings;
use Test::More;
use lib 't/lib';
use PeopleTest;
my $people_test = PeopleTest->new;
$people_test->log_disable('error');
my $mech = $people_test->get_mech;
check_error_400('/a8i2k282543jwd09awdj', 404);
check_error_400('/page/a8i2k282543jwd09awdj', 404);
sub check_error_400 {
my ( $path, $code ) = @_;
my $res = $mech->get($path);
ok($res->code == $code) or diag($res->code);
is($res->header('Pragma'), 'no-cache');
is($res->header('Cache-Control'), 'no-cache');
ok(defined $res->header('X-Robots-Tag'));
like($res->content, qr{meta.*robots.*noindex}i);
}
done_testing;
Tuesday, October 08, 2013