Test::MockClass

Test::MockClass is a Perl module to provide mock classes and mock objects for testing.
Download

Test::MockClass Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Jeremiah Jordan
  • Publisher web site:
  • http://search.cpan.org/~jjordan/Attribute-Method-Typeable-1.09/lib/Attribute/Method/Typeable.pm

Test::MockClass Tags


Test::MockClass Description

Test::MockClass is a Perl module to provide mock classes and mock objects for testing. Test::MockClass is a Perl module to provide mock classes and mock objects for testing.SYNOPSIS # Pass in the class name and version that you want to mock use Test::MockClass qw{ClassToMock 1.1}; # create a MockClass object to handle a specific class my $mockClass = Test::MockClass->new('ClassToMock'); # specify to inherit from a real class, or a mocked class: $mockClass->inheritFrom('IO::Socket'); # make a constructor for the class, can also use 'addMethod' for more control $mockClass->defaultConstructor(%classWideDefaults); # add a method: $mockClass->addMethod('methodname', $coderef); # add a simpler method, and specify return values that it will return automatically $mockClass->setReturnValues('methodname2', 'always', 3); # create an instance of the mocked class: my $mockObject = $mockClass->create(%instanceData); # set the desired call order for the methods: $mockClass->setCallOrder('methodname2', 'methodname', 'methodname'); # run tests using the mock Class elsewhere: #:in the class to test: sub objectFactory { return ClassToMock->new; } #:in your test code: assert($testObj->objectFactory->isa("ClassToMock")); # get the object Id for the rest of the methods: my $objectId = "$mockObject"; #or $objectId = $mockClass->getNextObjectId(); # verify that the methods were called in the correct order: if($mockClass->verifyCallOrder($objectId)) { # do something } # get the order that the methods were called: my @calls = $mockClass->getCallOrder($objectId); # get the list of arguments passed per call: my @argList = $mockClass->getArgumentList($objectId, 'methodname', $callPosition); # get the list of accesses made to a particular attribute (hashkey in $mockObject) my @accesses = $mockClass->getAttributeAccess($objectId, 'attribute'); Requirements: · Perl


Test::MockClass Related Software