Test::MockObject? What is that? How do I use? Why??? [Was: Devel::Cover recommendations...]
Adrian Howard
adrianh at quietstars.com
Mon Mar 19 09:39:40 GMT 2007
On 19 Mar 2007, at 08:40, Luis Motta Campos wrote:
> On Mar 17, 2007, at 9:40 PM, Adrian Howard wrote:
>> I think you want something like...
>>
>> use Test::MockObject;
>> my $mock = Test::MockObject->new->
>> mock( randommethod => sub { print "i like pie\n" } );
>> $mock->fake_module( 'MockedModule' );
>> $mock->fake_new( 'MockedModule' );
>>
>> MockedModule->new->randommethod;
>
> Please don't laught, but I can't see any good reason to use this
> on a test.
> Mr. Cantrell, could you please tell me how are you using this and
> why?
> Pointers and RTFM (with manual name) are welcome. ;-)
See <http://en.wikipedia.org/wiki/Mock_object> and <http://
www.martinfowler.com/bliki/TestDouble.html> for how using fake/mock/
stub modules can help you test your code.
Basically if Foo depends on Bar, it can be useful to make Bar do
exactly what you want (e.g. throw odd error conditions so you can
make sure you handle them correctly). Sometimes it can be hard to
make Bar do this - so using a mock/stub/fake of Bar can help.
Cheers
Adrian
More information about the london.pm
mailing list