Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

what and how mocking test is?

by xiaoyafeng (Chaplain)
on Jul 17, 2012 at 05:48 UTC ( #982139=perlquestion: print w/ replies, xml ) Need Help??
xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

Recently, I've modified a module of mine and want to do some tests. But what's stuck me is this module should connect to a database for initials, communicate with a remote DCOM server and apparently my notebook can't afford them.

I've heard mocking test long before. So can I complete this by mock tech.? if the answer is yes, where should I start? Any tutorials? any modules on cpan I can learn from?

Thanks a lot!!!

I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Comment on what and how mocking test is?
Re: what and how mocking test is?
by Khen1950fx (Canon) on Jul 17, 2012 at 06:38 UTC
Re: what and how mocking test is?
by Corion (Pope) on Jul 17, 2012 at 07:13 UTC

    Personally, I avoid mocking modules, because they add one more layer of indirection, and mocking up a single function isn't too hard:

    use Some::Module; use Test::More tests => 2; { my $some_function_called; local *some_function = sub { $some_function_called++; return @canned_results; }; my @res = other_function_that_calls_some_function(); is $some_function_called, 1, 'We asked for resource existence'; is_deeply \@res, ['expected', 'results'], 'We got good results'; }

    Of course, if you need to mock out large object functionality, one of the Mock modules might help you better, but I like to replace just the relevant parts of an object and have come to the conclusion that I best write my constructors and methods in a way such that I can pass in all "needed" objects or data as optional parameters. If they are not present, they get taken from elsewhere, but otherwise the passed-in values get used.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://982139]
Approved by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-09-20 06:42 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (155 votes), past polls