Developers with a background in Ruby on Rails and PHP are familiar with the concepts of mocking objects and setting expectations on them. The good news is that these powerful techniques for unit testing are available for Perl as well. Should I add you can find them on CPAN ? Before an example though, just a simple explanation about the topic. Unit testing “is a method by which individual units of source code are tested to determine if they are fit for use” (Wikipedia). It’s a common practice to perform unit testing in isolation ; in other words you focus testing on the source code, limiting as much as possible the interaction across modules or systems. It’s almost always practically impossible to test a class without instantiating other classes on which it depends or interacts. What can be done is mocking objects : creating “empty objects” that emulate the external behaviour of real objects. They must be able to “fool” the class under test and allow the creation of an exhaustive set ...