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

NAME

6       Test::Object - Thoroughly testing objects via registered handlers
7

SYNOPSIS

9         ###################################################################
10         # In your test module, register test handlers again class names   #
11         ###################################################################
12
13         package My::ModuleTester;
14
15         use Test::More;
16         use Test::Object;
17
18         # Foo::Bar is a subclass of Foo
19         Test::Object->register(
20               class => 'Foo',
21               tests => 5,
22               code  => \&foo_ok,
23               );
24         Test::Object->register(
25               class => 'Foo::Bar',
26               # No fixed number of tests
27               code  => \&foobar_ok,
28               );
29
30         sub foo_ok {
31               my $object = shift;
32               ok( $object->foo, '->foo returns true' );
33         }
34
35         sub foobar_ok {
36               my $object = shift;
37               is( $object->foo, 'bar', '->foo returns "bar"' );
38         }
39
40         1;
41
42
43
44         ###################################################################
45         # In test script, test object against all registered classes      #
46         ###################################################################
47
48         #!/usr/bin/perl -w
49
50         use Test::More 'no_plan';
51         use Test::Object;
52         use My::ModuleTester;
53
54         my $object = Foo::Bar->new;
55         isa_ok( $object, 'Foo::Bar' );
56         object_ok( $object );
57

DESCRIPTION

59       In situations where you have deep trees of classes, there is a common
60       situation in which you test a module 4 or 5 subclasses down, which
61       should follow the correct behaviour of not just the subclass, but of
62       all the parent classes.
63
64       This should be done to ensure that the implementation of a subclass has
65       not somehow "broken" the object's behaviour in a more general sense.
66
67       "Test::Object" is a testing package designed to allow you to easily
68       test what you believe is a valid object against the expected behaviour
69       of all of the classes in its inheritance tree in one single call.
70
71       To do this, you "register" tests (in the form of CODE or function
72       references) with "Test::Object", with each test associated with a
73       particular class.
74
75       When you call "object_ok" in your test script, "Test::Object" will
76       check the object against all registered tests. For each class that your
77       object responds to "$object->isa($class)" for, the appropriate testing
78       function will be called.
79
80       Doing it this way allows adapter objects and other things that respond
81       to "isa" differently that the default to still be tested against the
82       classes that it is advertising itself as correctly.
83
84       This also means that more than one test might be "counted" for each
85       call to "object_ok". You should account for this correctly in your
86       expected test count.
87

SUPPORT

89       Bugs should be submitted via the CPAN bug tracker, located at
90
91       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Object>
92
93       For other issues, contact the author.
94

AUTHOR

96       Adam Kennedy <cpan@ali.as>
97

SEE ALSO

99       <http://ali.as/>, Test::More, Test::Builder::Tester, Test::Class
100
102       Copyright 2005, 2006 Adam Kennedy. All rights reserved.
103
104       This program is free software; you can redistribute it and/or modify it
105       under the same terms as Perl itself.
106
107       The full text of the license can be found in the LICENSE file included
108       with this module.
109
110
111
112perl v5.16.3                      2006-09-07                   Test::Object(3)
Impressum