weblog.masukomi.org

mah-soo-koh-me

 

How to create a Test Suite in Perl’s Test::Unit v0.25 April 9, 2008

Filed under: Uncategorized — masukomi @ 1:31 pm

If your Test Case is a package whose goal is to test all aspects of a particular class then a Test Suite is something which kicks off a collection of related Test Cases. As with most things in Test::Unit it’s really easy to do and also terribly documented. So, without further ado…

You need something to kick off all your tests:

-----------------------

use Test::Unit::HarnessUnit;
use My::Test::Suite::Package;

my $testrunner = Test::Unit::HarnessUnit->new();
$testrunner->start("My::Test::Suite::Package");

-----------------------

Next you need the test suite it’s going to kick off:

-----------------------

package My::Test::Suite::Package;
use base qw/Test::Unit::TestSuite/;

# returns an array of the fully qualified names of the TestCase
# based classes you wish to run.
sub include_tests() {
    return ('Some::Test::Case',
        'Some::Test::Case2',
        'Some::Test::Case3);
}

1;

-----------------------

That’s it. Happy testing.

 

1 Comment for this post

 
Aristotle Pagaltzis Says:

Hi Kate,

please don’t use Test::Unit. It’s largely unmaintained and does not integrate with the rest of the Perl testing landscape. If you want an nUnit-alike, it’s better to pick up Test::Class instead – it’s maintained, it plays well with Test::Builder-based testing modules (the CPAN default way of doing things), it emits TAP as expected in Perl-land, and it offers a more convenient rendition of the nUnit interface.

Leave a Reply