Test::...stSuite(3pm)
πΈ Test::...stSuite(3pm) π
okay bestie, this is the perl page for Test::Unit::TestSuite, straight out of the User Contributed Perl Documentation collection, and it's genuinely iconic. it's the unit testing framework base class, and no cap, it's giving "build me a whole test suite with barely any effort" energy. let's get into it π«Ά
β¨ NAME β¨
Test::Unit::TestSuite β unit testing framework base class π
π SYNOPSIS π
package MySuite;
use base qw(Test::Unit::TestSuite);
sub name { 'My very own test suite' }
sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }
this is literally the easiest way of building suites, bestie; there are many more. read on... π
π¦ DESCRIPTION π¦
this class provides the functionality for building test suites in several different ways. pick your fighter, they're all valid π
any module can be a test suite runnable by the framework if it provides a suite() method which returns a Test::Unit::TestSuite object, e.g.
use Test::Unit::TestSuite;
# more code here ...
sub suite {
my $class = shift;
# Create an empty suite.
my $suite = Test::Unit::TestSuite->empty_new("A Test Suite");
# Add some tests to it via $suite->add_test() here
return $suite;
}
this is useful if you want your test suite to be contained in the module it tests, for example. self-contained queen behavior β¨
alternatively, you can have "standalone" test suites, which inherit directly from Test::Unit::TestSuite, e.g.:
package MySuite;
use base qw(Test::Unit::TestSuite);
sub new {
my $class = shift;
my $self = $class->SUPER::empty_new();
# Build your suite here
return $self;
}
sub name { 'My very own test suite' }
or if your new() is going to do nothing more interesting than add tests from other suites and testcases via add_test(), you can use the include_tests() method as shorthand:
package MySuite;
use base qw(Test::Unit::TestSuite);
sub name { 'My very own test suite' }
sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }
this is the easiest way of building suites. periodt. π
π CONSTRUCTORS π
π empty_new ([NAME])
my $suite = Test::Unit::TestSuite->empty_new('my suite name');
creates a fresh suite with no tests. brand new, blank slate, main character energy π
π new ([ CLASSNAME | TEST ])
if a test suite is provided as the argument, it merely returns that suite. if a test case is provided, it extracts all test case methods from the test case (see "list_tests" in Test::Unit::TestCase) into a new test suite, bestie.
if the class this method is being run in has an "include_tests" method which returns an array of class names, it will also automatically add the tests from those classes into the newly constructed suite object. auto-magic, we love to see it β¨
π METHODS π
π§ name()
returns the suite's human-readable name. cute and legible, as it should be πΈ
π§ names()
returns an arrayref of the names of all tests in the suite. all of them, no gatekeeping π
π§ list (SHOW_TESTCASES)
produces a human-readable indented lists of the suite and the subsuites it contains. if the first parameter is true, also lists any testcases contained in the suite and its subsuites. so like, pass a truthy first arg if you want the full receipts π
π§ add_test (TEST_CLASSNAME | TEST_OBJECT)
you can add a test object to a suite with this method, by passing either its classname, or the object itself as the argument.
of course, there are many ways of getting the object too ...
# Get and add an existing suite.
$suite->add_test('MySuite1');
# This is exactly equivalent:
$suite->add_test(Test::Unit::TestSuite->new('MySuite1'));
# So is this, provided MySuite1 inherits from Test::Unit::TestSuite.
use MySuite1;
$suite->add_test(MySuite1->new());
# Extract yet another suite by way of suite() method and add it to
# $suite.
use MySuite2;
$suite->add_test(MySuite2->suite());
# Extract test case methods from MyModule::TestCase into a
# new suite and add it to $suite.
$suite->add_test(Test::Unit::TestSuite->new('MyModule::TestCase'));
obsessed with the range honestly π₯
π AUTHOR π
copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see Test::Unit or the AUTHORS file included in this distribution).
all rights reserved. this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, and legally so β¨
π SEE ALSO π
Test::Unit::TestRunnerTest::Unit::TkTestRunner- for further examples, take a look at the framework self test collection (
t::tlib::AllTests). bestie, the examples are right there, go look π«Ά
and that's the whole page, bestie π this was perl v5.40.1, dated 2026-04-05, and the page goes by Test::...stSuite(3pm). mwah, go build a beautiful suite ππΈ
π¦ where this page comes from
- ubuntu stonking: libtest-unit-perl 0.30-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms