in reply to what and how mocking test is?
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.
|
|---|