Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
ABOUT THIS TUTORIALUnit testing on object aggregations are usually hard to develop because you may need to instantiate several complex objects, so you may wind up doing integral testing in order to test some very specific subclass. Test::MockObject, written by chromatic was designed to aid with this situation, nevertheless some things may not be immediately apparent for the novice user. Also, if you are testing OO stuff that uses accessors (Class::Accessor, Moose, etc.) you may find it difficult to do so. This tutorial is targeted for example to Moose developers, who will frequently encounter accessors and isa validations (see Moose::Manual::Attributes). CAVEATSUnit testing does not excuse you from doing integral testing with the real objects. Just as the author of Test::MockObject warned me before writing this tutorial: "if you have to mock an accessor, you're probably mocking too much" Re: RFC Mocking an Accessor with Test::MockObject. So, you have been warned. Please revise the pod for Test::MockObject and Test::MockObject::Extends before using the techniques explained here. THE METHODTest::MockObject allows you to create objects that mock certain specific functionality, and that don't depend on anything more than the Test::MockObject module. It also allows for you to cheat Perl into thinking that a package has already been loaded, preventing Perl from doing so in your test, and forcing it to use your mocked package instead. More so, you can also fiddle with the mocked object's isa so that your mocked objects may pass UNIVERSAL->isa validations in the target code. What Test::MockObject does not currently do, is provide a simple mechanism to emulate accessors. Here is one method to do it, maybe not the best, but will do the job. The example is mocking an object that uses another object which is also mocked, showing off some of the the powers of Test::MockObject.
In reply to Mocking accessors with Test::MockObject by ait
|
|