Thank you for the links kaif and eyepopslikeamosquito

In a unit testing context, I could not figure out how to effectively use any of the pre-made Mock object modules available at CPAN. My own cooked up method using Class::Struct (see top node) seems to do the same thing.

For instance, the following code doesn't see to do any more than what using Class::Struct would do:

my $mock = Test::MockObject->new(); $mock->mock( 'fluorinate', sub { 'impurifying precious bodily fluids' } ); print $mock->fluorinate;

Test::MockObject is at http://search.cpan.org/~chromatic/Test-MockObject-0.20/lib/Test/MockObject.pm

I mean, if we compare the two approaches we see very little difference. Class::Struct automates the creation of accessor methods; so does Test::MockObject. They both create a blessed hash reference by default.

They also have their differences. Adding subroutines (like init) is straight-forward using Class::Struct, whereas Test::MockObject would have the programmer creating wierdness with set_true, set_false, set_always, etc.

To my eye, this doesn't look very clean.

Test::MockObject does do something Class::Struct does not: it keeps track of any method calls to a Mock Object. I'm not sure why this is so useful anyway from the standpoint of unit testing.

Can someone with more experience shed light on the subject?


In reply to Re^2: testing with mock objects by oopplz
in thread testing with mock objects by oopplz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.