6. テスト鵐皀献紿`ル
package SomeModule;
use strict;
use warnings;
sub new {
my ($class, %args) = @_;
bless %args, $class;
}
sub sum {
my $self = shift;
my $ret = 0;
for my $num (@_) {
$ret += $num;
}
return $ret;
}
1;
7. テスト1 useできる
# t/01_use.t
use strict;
use warnings;
use Test::More;
use_ok('SomeModule');
done_testing;
$ perl -Ilib t/01_use.t
ok 1 - use SomeModule;
1..1
8. テスト2 newできる
# t/02_new.t
use strict;
use warnings;
use Test::More;
use SomeModule;
my $obj = SomeModule->new;
isa_ok $obj, 'SomeModule';
done_testing;
$ perl -Ilib t/02_new.t
ok 1 - The object isa SomeModule
1..1
9. テスト3 C嬬は屎しく咾
# t/03_sum.t
use strict;
use warnings;
use Test::More;
use SomeModule;
my $obj = SomeModule->new;
subtest 'basic' => sub {
my $got = $obj->sum(1, 2, 3);
is $got, 6;
};
done_testing;
$ perl -Ilib t/03_sum.t
ok 1
1..1
ok 1 - basic
1..1
10. まとめてテスト
$ prove -lc t
t/01_use.t .. ok
t/02_new.t .. ok
t/03_sum.t .. ok
All tests successful.
Files=3, Tests=5, 0 wallclock secs ( 0.10 usr 0.02 sys + 0.20 cusr 0.05 csys = 0.37 CPU)
Result: PASS
15. t/01_root.t
use strict;
use warnings;
use utf8;
use t::Util;
use Plack::Test;
use Plack::Util;
use Test::More;
my $app = Plack::Util::load_psgi 'app.psgi';
test_psgi
app => $app,
client => sub {
my $cb = shift;
my $req = HTTP::Request->new(GET => 'http://localhost/');
my $res = $cb->($req);
is $res->code, 200;
diag $res->content if $res->code != 200;
};
done_testing;
17. t/02_mech.t
use strict;
use warnings;
use utf8;
use t::Util;
use Plack::Test;
use Plack::Util;
use Test::More;
use Test::Requires 'Test::WWW::Mechanize::PSGI';
my $app = Plack::Util::load_psgi 'app.psgi';
my $mech = Test::WWW::Mechanize::PSGI->new(app => $app);
$mech->get_ok('/');
done_testing();