1Test::Unit::TestSuite(3U)ser Contributed Perl DocumentatiToenst::Unit::TestSuite(3)
2
3
4

NAME

6       Test::Unit::TestSuite - unit testing framework base class
7

SYNOPSIS

9           package MySuite;
10
11           use base qw(Test::Unit::TestSuite);
12
13           sub name { 'My very own test suite' }
14           sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }
15
16       This is the easiest way of building suites; there are many more.  Read
17       on ...
18

DESCRIPTION

20       This class provides the functionality for building test suites in
21       several different ways.
22
23       Any module can be a test suite runnable by the framework if it provides
24       a "suite()" method which returns a "Test::Unit::TestSuite" object, e.g.
25
26           use Test::Unit::TestSuite;
27
28           # more code here ...
29
30           sub suite {
31               my $class = shift;
32
33               # Create an empty suite.
34               my $suite = Test::Unit::TestSuite->empty_new("A Test Suite");
35               # Add some tests to it via $suite->add_test() here
36
37               return $suite;
38           }
39
40       This is useful if you want your test suite to be contained in the
41       module it tests, for example.
42
43       Alternatively, you can have "standalone" test suites, which inherit
44       directly from "Test::Unit::TestSuite", e.g.:
45
46           package MySuite;
47
48           use base qw(Test::Unit::TestSuite);
49
50           sub new {
51               my $class = shift;
52               my $self = $class->SUPER::empty_new();
53               # Build your suite here
54               return $self;
55           }
56
57           sub name { 'My very own test suite' }
58
59       or if your "new()" is going to do nothing more interesting than add
60       tests from other suites and testcases via "add_test()", you can use the
61       "include_tests()" method as shorthand:
62
63           package MySuite;
64
65           use base qw(Test::Unit::TestSuite);
66
67           sub name { 'My very own test suite' }
68           sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }
69
70       This is the easiest way of building suites.
71

CONSTRUCTORS

73   empty_new ([NAME])
74           my $suite = Test::Unit::TestSuite->empty_new('my suite name');
75
76       Creates a fresh suite with no tests.
77
78   new ([ CLASSNAME | TEST ])
79       If a test suite is provided as the argument, it merely returns that
80       suite.  If a test case is provided, it extracts all test case methods
81       from the test case (see "list_tests" in Test::Unit::TestCase) into a
82       new test suite.
83
84       If the class this method is being run in has an "include_tests" method
85       which returns an array of class names, it will also automatically add
86       the tests from those classes into the newly constructed suite object.
87

METHODS

89   name()
90       Returns the suite's human-readable name.
91
92   names()
93       Returns an arrayref of the names of all tests in the suite.
94
95   list (SHOW_TESTCASES)
96       Produces a human-readable indented lists of the suite and the subsuites
97       it contains.  If the first parameter is true, also lists any testcases
98       contained in the suite and its subsuites.
99
100   add_test (TEST_CLASSNAME | TEST_OBJECT)
101       You can add a test object to a suite with this method, by passing
102       either its classname, or the object itself as the argument.
103
104       Of course, there are many ways of getting the object too ...
105
106           # Get and add an existing suite.
107           $suite->add_test('MySuite1');
108
109           # This is exactly equivalent:
110           $suite->add_test(Test::Unit::TestSuite->new('MySuite1'));
111
112           # So is this, provided MySuite1 inherits from Test::Unit::TestSuite.
113           use MySuite1;
114           $suite->add_test(MySuite1->new());
115
116           # Extract yet another suite by way of suite() method and add it to
117           # $suite.
118           use MySuite2;
119           $suite->add_test(MySuite2->suite());
120
121           # Extract test case methods from MyModule::TestCase into a
122           # new suite and add it to $suite.
123           $suite->add_test(Test::Unit::TestSuite->new('MyModule::TestCase'));
124

AUTHOR

126       Copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see
127       Test::Unit or the AUTHORS file included in this distribution).
128
129       All rights reserved. This program is free software; you can
130       redistribute it and/or modify it under the same terms as Perl itself.
131

SEE ALSO

133       ·   Test::Unit::TestRunner
134
135       ·   Test::Unit::TkTestRunner
136
137       ·   For further examples, take a look at the framework self test
138           collection (t::tlib::AllTests).
139
140
141
142perl v5.32.0                      2020-07-28          Test::Unit::TestSuite(3)
Impressum