in reply to Re: Smallish mock objects
in thread Smallish mock objects
I do realize that some module simple can't be loaded easily (some of the Apache ones, for example), so mock objects would be appropriate there, but otherwise, I don't think it's worth the trouble.
I only find myself using them when I have some state in the "mock" object that's hard to reproduce in a "live" object (e.g rare error conditions, etc.) or when I'm dealing with third party code.
I have to admit I rarely use any of the CPAN modules for mocking and do something like:
{ package MockFoo; sub new { bless {}, shift } sub rarely_returns_42 { return 42 } } my $mock = MockFoo->new;
rather than:
use Test::MockObject; my $mock = Test::MockObject->new->set_always( rarely_returns_42 => 42 );
Probably because I don't use them enough for the API to be familiar to me.
The pro-/anti-mock argument seems to occur every few months on the TDD mailing list :-) Google around for "state based testing" vs "interaction based testing".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Smallish mock objects
by sgt (Deacon) on Dec 20, 2006 at 10:02 UTC | |
by sgt (Deacon) on Dec 20, 2006 at 11:33 UTC | |
by adrianh (Chancellor) on Dec 23, 2006 at 11:57 UTC | |
by sgt (Deacon) on Dec 23, 2006 at 15:01 UTC |