1Test::Unit::Procedural(U3s)er Contributed Perl DocumentatTieosnt::Unit::Procedural(3)
2
3
4
6 Test::Unit::Procedural - Procedural style unit testing interface
7
9 use Test::Unit::Procedural;
10
11 # your code to be tested goes here
12
13 sub foo { return 23 };
14 sub bar { return 42 };
15
16 # define tests
17
18 sub test_foo { assert(foo() == 23, "Your message here"); }
19 sub test_bar { assert(bar() == 42, "I will be printed if this fails"); }
20
21 # set_up and tear_down are used to
22 # prepare and release resources need for testing
23
24 sub set_up { print "hello world\n"; }
25 sub tear_down { print "leaving world again\n"; }
26
27 # run your test
28
29 create_suite();
30 run_suite();
31
33 Test::Unit::Procedural is the procedural style interface to a
34 sophisticated unit testing framework for Perl that is derived from the
35 JUnit testing framework for Java by Kent Beck and Erich Gamma. While
36 this framework is originally intended to support unit testing in an
37 object-oriented development paradigm (with support for inheritance of
38 tests etc.), Test::Unit::Procedural is intended to provide a simpler
39 interface to the framework that is more suitable for use in a scripting
40 style environment. Therefore, Test::Unit::Procedural does not provide
41 much support for an object-oriented approach to unit testing - if you
42 want that, please have a look at Test::Unit::TestCase.
43
44 You test a given unit (a script, a module, whatever) by using
45 Test::Unit::Procedural, which exports the following routines into your
46 namespace:
47
48 assert()
49 used to assert that a boolean condition is true
50
51 create_suite()
52 used to create a test suite consisting of all methods with a name
53 prefix of "test"
54
55 run_suite()
56 runs the test suite (text output)
57
58 add_suite()
59 used to add test suites to each other
60
61 For convenience, "create_suite()" will automatically build a test suite
62 for a given package. This will build a test case for each subroutine in
63 the package given that has a name starting with "test" and pack them
64 all together into one TestSuite object for easy testing. If you dont
65 give a package name to "create_suite()", the current package is taken
66 as default.
67
68 Test output is one status line (a "." for every successful test run, or
69 an "F" for any failed test run, to indicate progress), one result line
70 ("OK" or "!!!FAILURES!!!"), and possibly many lines reporting detailed
71 error messages for any failed tests.
72
73 Please remember, Test::Unit::Procedural is intended to be a simple and
74 convenient interface. If you need more functionality, take the object-
75 oriented approach outlined in Test::Unit::TestCase.
76
78 Copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see
79 Test::Unit or the AUTHORS file included in this distribution).
80
81 All rights reserved. This program is free software; you can
82 redistribute it and/or modify it under the same terms as Perl itself.
83
85 · Test::Unit::TestCase
86
87 · the procedural style examples in the examples directory
88
89
90
91perl v5.30.1 2020-01-30 Test::Unit::Procedural(3)