[Israel.pm] Testing problem

Ran Eilam eilara at cortext.co.il
Tue Jan 6 06:27:44 PST 2004

> I think that the Ran solution with mocking open() has the 
> same problem, how to return the valid file handler and the
> subprocess pid without actually running some real process,
> like "cat expected_output_file".

Ah, so that is the difference vs. mocking time(), which only returns a

As Shlomi said you need to mock the pid and filehandle as well.

> And all this new non-trivial code (that should be tested too) just to
> emulate `cat file` that you know works without bugs.

Yes but the code is reusable- and there is a CPAN MockObject module
which does most of this. It is already tested.

And there are costs associated with the 'echo' trick:

* fixture needs to create a disk area for the test files, and remove it
after tests are run

* you now need to maintain the expected_output file

* tests are slower, if you have many, it can be an order of magnitude

> Maybe on the meeting we will have some minutes to speak about when it
> worth to create new classes just for testing, when new wrappers, and
> just to add "if $ENV{DEBUG}" lines to the code.

Cool. Looking at all the options raised so far, it seems the 'echo'
trick is best, but only Thomas can choose, as he has all the forces.

Actually I am moving away from 'mock everything' approach and testing in
complete isolation, into a more pragmatic approach, something like this:



More information about the Perl mailing list