Test::Class is a Perl module that allows you to easily create test classes in an xUnit/JUnit style.
SYNOPSIS
package Example::Test;
use base qw(Test::Class);
use Test::More;
# setup methods are run before every test method.
sub make_fixture : Test(setup) {
my $array = [1, 2];
shift->{test_array} = $array;
};
# a test method that runs 1 test
sub test_push : Test {
my $array = shift->{test_array};
push @$array, 3;
is_deeply($array, [1, 2, 3], 'push worked');
};
# a test method that runs 4 tests
sub test_pop : Test(4) {
my $array = shift->{test_array};
is(pop @$array, 2, 'pop = 2');
is(pop @$array, 1, 'pop = 1');
is_deeply($array, [], 'array empty');
is(pop @$array, undef, 'pop = undef');
};
# teardown methods are run after every test method.
sub teardown : Test(teardown) {
my $array = shift->{test_array};
diag("array = (@$array) after test(s)");
};
later in a nearby .t file
#! /usr/bin/perl
use Example::Test;
# run all the test methods in Example::Test
Test::Class->runtests;
Outputs:
1..5
ok 1 - pop = 2
ok 2 - pop = 1
ok 3 - array empty
ok 4 - pop = undef
# array = () after test(s)
ok 5 - push worked
# array = (1 2 3) after test(s)
Product's homepage
Requirements:
· Perl