Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

test::object(3pm) [debian man page]

Test::Object(3pm)					User Contributed Perl Documentation					 Test::Object(3pm)

NAME
Test::Object - Thoroughly testing objects via registered handlers SYNOPSIS
################################################################### # In your test module, register test handlers again class names # ################################################################### package My::ModuleTester; use Test::More; use Test::Object; # Foo::Bar is a subclass of Foo Test::Object->register( class => 'Foo', tests => 5, code => &foo_ok, ); Test::Object->register( class => 'Foo::Bar', # No fixed number of tests code => &foobar_ok, ); sub foo_ok { my $object = shift; ok( $object->foo, '->foo returns true' ); } sub foobar_ok { my $object = shift; is( $object->foo, 'bar', '->foo returns "bar"' ); } 1; ################################################################### # In test script, test object against all registered classes # ################################################################### #!/usr/bin/perl -w use Test::More 'no_plan'; use Test::Object; use My::ModuleTester; my $object = Foo::Bar->new; isa_ok( $object, 'Foo::Bar' ); object_ok( $object ); DESCRIPTION
In situations where you have deep trees of classes, there is a common situation in which you test a module 4 or 5 subclasses down, which should follow the correct behaviour of not just the subclass, but of all the parent classes. This should be done to ensure that the implementation of a subclass has not somehow "broken" the object's behaviour in a more general sense. "Test::Object" is a testing package designed to allow you to easily test what you believe is a valid object against the expected behaviour of all of the classes in its inheritance tree in one single call. To do this, you "register" tests (in the form of CODE or function references) with "Test::Object", with each test associated with a partic- ular class. When you call "object_ok" in your test script, "Test::Object" will check the object against all registered tests. For each class that your object responds to "$object->isa($class)" for, the appropriate testing function will be called. Doing it this way allows adapter objects and other things that respond to "isa" differently that the default to still be tested against the classes that it is advertising itself as correctly. This also means that more than one test might be "counted" for each call to "object_ok". You should account for this correctly in your expected test count. SUPPORT
Bugs should be submitted via the CPAN bug tracker, located at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Object> For other issues, contact the author. AUTHOR
Adam Kennedy <cpan@ali.as> SEE ALSO
<http://ali.as/>, Test::More, Test::Builder::Tester, Test::Class COPYRIGHT
Copyright 2005, 2006 Adam Kennedy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.8.8 2006-09-06 Test::Object(3pm)

Check Out this Related Man Page

Test::SubCalls(3pm)					User Contributed Perl Documentation				       Test::SubCalls(3pm)

NAME
Test::SubCalls - Track the number of times subs are called SYNOPSIS
use Test::SubCalls; # Start tracking calls to a named sub sub_track( 'Foo::foo' ); # Run some test code ... # Test that some sub deep in the codebase was called # a specific number of times. sub_calls( 'Foo::foo', 5 ); sub_calls( 'Foo::foo', 5, 'Use a custom test message' ); # Reset the counts for one or all subs sub_reset( 'Foo::foo' ); sub_reset_all(); DESCRIPTION
There are a number of different situations (like testing caching code) where you want to want to do a number of tests, and then verify that some underlying subroutine deep within the code was called a specific number of times. This module provides a number of functions for doing testing in this way in association with your normal Test::More (or similar) test scripts. FUNCTIONS
In the nature of test modules, all functions are exported by default. sub_track $subname The "sub_track" function creates a new call tracker for a named function. The sub to track must be provided by name, references to the function itself are insufficient. Returns true if added, or dies on error. sub_calls $subname, $expected_calls [, $message ] The "sub_calls" function is the primary (and only) testing function provided by "Test::SubCalls". A single call will represent one test in your plan. It takes the subroutine name as originally provided to "sub_track", the expected number of times the subroutine should have been called, and an optional test message. If no message is provided, a default message will be provided for you. Test is ok if the number of times the sub has been called matches the expected number, or not ok if not. sub_reset $subname To prevent repeat users from having to take before and after counts when they start testing from after zero, the "sub_reset" function has been provided to reset a sub call counter to zero. Returns true or dies if the sub name is invalid or not currently tracked. sub_reset_all Provided mainly as a convenience, the "sub_reset_all" function will reset all the counters currently defined. Returns true. SUPPORT
Bugs should be submitted via the CPAN bug tracker, located at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls> For other issues, or commercial enhancement or support, contact the author. AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
<http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap COPYRIGHT
Copyright 2005 - 2009 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.10.1 2009-04-19 Test::SubCalls(3pm)
Man Page