|
NAMETest::MockModule - Override subroutines in a module for unit testingSYNOPSISuse Module::Name; use Test::MockModule; { my $module = Test::MockModule->new('Module::Name'); $module->mock('subroutine', sub { ... }); Module::Name::subroutine(@args); # mocked #Same effect, but this will die() if other_subroutine() #doesn't already exist, which is often desirable. $module->redefine('other_subroutine', sub { ... }); } Module::Name::subroutine(@args); # original subroutine # Working with objects use Foo; use Test::MockModule; { my $mock = Test::MockModule->new('Foo'); $mock->mock(foo => sub { print "Foo!\n"; }); my $foo = Foo->new(); $foo->foo(); # prints "Foo!\n" } DESCRIPTION"Test::MockModule" lets you temporarily redefine subroutines in other packages for the purposes of unit testing.A "Test::MockModule" object is set up to mock subroutines for a given module. The object remembers the original subroutine so it can be easily restored. This happens automatically when all MockModule objects for the given module go out of scope, or when you "unmock()" the subroutine. METHODS
SEE ALSOTest::MockObject::ExtendsSub::Override AUTHORSCurrent Maintainer: Geoff Franks <gfranks@cpan.org>Original Author: Simon Flack <simonflk _AT_ cpan.org> COPYRIGHTCopyright 2004 Simon Flack <simonflk _AT_ cpan.org>. All rights reservedYou may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Visit the GSP FreeBSD Man Page Interface. |