1Test::Class::Most(3)  User Contributed Perl Documentation Test::Class::Most(3)
2
3
4

NAME

6       Test::Class::Most - Test Classes the easy way
7

VERSION

9       Version 0.08
10

SYNOPSIS

12       Instead of this:
13
14           use strict;
15           use warnings;
16           use Test::Exception 0.88;
17           use Test::Differences 0.500;
18           use Test::Deep 0.106;
19           use Test::Warn 0.11;
20           use Test::More 0.88;
21
22           use parent 'My::Test::Class';
23
24           sub some_test : Tests { ... }
25
26       You type this:
27
28           use Test::Class::Most parent => 'My::Test::Class';
29
30           sub some_test : Tests { ... }
31

DESCRIPTION

33       When people write test classes with the excellent "Test::Class", you
34       often see the following at the top of the code:
35
36         package Some::Test::Class;
37
38         use strict;
39         use warnings;
40         use base 'My::Test::Class';
41         use Test::More;
42         use Test::Exception;
43
44         # and then the tests ...
45
46       That's a lot of boilerplate and I don't like boilerplate.  So now you
47       can do this:
48
49         use Test::Class::Most parent => 'My::Test::Class';
50
51       That automatically imports strict and warnings for you.  It also gives
52       you all of the testing goodness from Test::Most.
53

CREATING YOUR OWN BASE CLASS

55       You probably want to create your own base class for testing.  To do
56       this, simply specify no import list:
57
58         package My::Test::Class;
59         use Test::Class::Most; # we now inherit from Test::Class
60
61         INIT { Test::Class->runtests }
62
63         1;
64
65       And then your other classes inherit as normal (well, the way we do it):
66
67         package Tests::For::Foo;
68         use Test::Class::Most parent => 'My::Test::Class';
69
70       And you can inherit from those other classes, too:
71
72         package Tests::For::Foo::Child;
73         use Test::Class::Most parent => 'Tests::For::Foo';
74
75       Of course, it's quite possible that you're a fan of multiple
76       inheritance, so you can do that, too (I was soooooo tempted to not
77       allow this, but I figured I shouldn't force too many of my personal
78       beliefs on you):
79
80        package Tests::For::ISuckAtOO;
81        use Test::Class::Most parent => [qw/
82           Tests::For::Foo
83           Tests::For::Bar
84           Some::Other::Class::For::Increased::Stupidity
85        /];
86
87       As a side note, it's recommended that even if you don't need test
88       control methods in your base class, put stubs in there:
89
90         package My::Test::Class;
91         use Test::Class::Most; # we now inherit from Test::Class
92
93         INIT { Test::Class->runtests }
94
95         sub startup  : Tests(startup)  {}
96         sub setup    : Tests(setup)    {}
97         sub teardown : Tests(teardown) {}
98         sub shutdown : Tests(shutdown) {}
99
100         1;
101
102       This allows developers to always be able to safely call parent test
103       control methods rather than wonder if they are there:
104
105         package Tests::For::Customer;
106         use Test::Class::Most parent => 'My::Test::Class';
107
108         sub setup : Tests(setup) {
109           my $test = shift;
110           $test->next::method; # safe due to stub in base class
111           ...
112         }
113

ATTRIBUTES

115       You can also specify "attributes" which are merely very simple
116       getter/setters.
117
118         use Test::Class::Most
119           parent      => 'My::Test::Class',
120           attributes  => [qw/customer items/],
121           is_abstract => 1;
122
123         sub setup : Tests(setup) {
124           my $test = shift;
125           $test->SUPER::setup;
126           $test->customer( ... );
127           $test->items( ... );
128         }
129
130         sub some_tests : Tests {
131           my $test     = shift;
132           my $customer = $test->customer;
133           ...
134         }
135
136       If called with no arguments, returns the current value.  If called with
137       one argument, sets that argument as the current value.  If called with
138       more than one argument, it croaks.
139

ABSTRACT CLASSES

141       You may pass an optional "is_abstract" parameter in the import list. It
142       takes a boolean value. This value is advisory only and is not
143       inherited. It defaults to false if not provided.
144
145       Sometimes you want to identify a test class as "abstract". It may have
146       a bunch of tests, but those should only run for its subclasses. You can
147       pass "<is_abstract =" 1>> in the import list. Then, to test if a given
148       class or instance of that class is "abstract":
149
150        sub dont_run_in_abstract_base_class : Tests {
151            my $test = shift;
152            return if Test::Class::Most->is_abstract($test);
153            ...
154        }
155
156       Note that "is_abstract" is strictly advisory only. You are expected
157       (required) to check the value yourself and take appropriate action.
158
159       We recommend adding the following method to your base class:
160
161        sub is_abstract {
162            my $test = shift;
163            return Test::Class::Most->is_abstract($test);
164        }
165
166       And later in a subclass:
167
168        if ( $test->is_abstract ) { ... }
169

EXPORT

171       All functions from Test::Most are automatically exported into your
172       namespace.
173

TUTORIAL

175       If you're not familiar with using Test::Class, please see my tutorial
176       at:
177
178       •   <http://www.modernperlbooks.com/mt/2009/03/organizing-test-suites-with-testclass.html>
179
180       •   <http://www.modernperlbooks.com/mt/2009/03/reusing-test-code-with-testclass.html>
181
182       •   <http://www.modernperlbooks.com/mt/2009/03/making-your-testing-life-easier.html>
183
184       •   <http://www.modernperlbooks.com/mt/2009/03/using-test-control-methods-with-testclass.html>
185
186       •   <http://www.modernperlbooks.com/mt/2009/03/working-with-testclass-test-suites.html>
187

AUTHOR

189       Curtis "Ovid" Poe, "<ovid at cpan.org>"
190

BUGS

192       Please report any bugs or feature requests to "bug-test-class-most at
193       rt.cpan.org", or through the web interface at
194       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Class-Most>.  I
195       will be notified, and then you'll automatically be notified of progress
196       on your bug as I make changes.
197

SUPPORT

199       You can find documentation for this module with the perldoc command.
200
201           perldoc Test::Class::Most
202
203       You can also look for information at:
204
205       •   RT: CPAN's request tracker
206
207           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Class-Most>
208
209       •   AnnoCPAN: Annotated CPAN documentation
210
211           <http://annocpan.org/dist/Test-Class-Most>
212
213       •   CPAN Ratings
214
215           <http://cpanratings.perl.org/d/Test-Class-Most>
216
217       •   Search CPAN
218
219           <http://search.cpan.org/dist/Test-Class-Most/>
220

SEE ALSO

222       •   Test::Class
223
224           xUnit-style testing in Perl
225
226       •   Test::Most
227
228           The most popular CPAN test modules bundled into one module.
229
230       •   Modern::Perl
231
232           I stole this code.  Thanks "chromatic"!
233

ACKNOWLEDGEMENTS

235       Thanks to Adrian Howard for Test::Class, Adam Kennedy for maintaining
236       it and "chromatic" for Modern::Perl.
237
239       Copyright 2010 Curtis "Ovid" Poe, all rights reserved.
240
241       This program is free software; you can redistribute it and/or modify it
242       under the same terms as Perl itself.
243
244
245
246perl v5.36.0                      2022-07-22              Test::Class::Most(3)
Impressum