[mocha-developer] Stubbing objects and calling to_json on them errors (circular reference)
bkocik at gmail.com
Fri Oct 24 09:26:38 EDT 2008
Please don't apologize - this is probably the best, most well-
delivered advice I've ever received from a mailing list, and I greatly
appreciate it. I've actually sort of thought the same thing; what I'm
doing now is testing implementation rather than results, and while I
knew it wasn't what I should be doing I wasn't quite sure what that
thing I should be doing was.
Thanks very much for taking the time to spell some of this out for me.
You've taught me something, which I'm grateful for, and I'm going to
share your advice with my direct manager and suggest that we consider
a change in testing focus.
On 24 Oct, 2008, at 8:49 AM, John D. Hume wrote:
> On Mon, Oct 20, 2008 at 3:10 PM, Bill Kocik <bkocik at gmail.com> wrote:
>> Our first step in the cleanup effort is to
>> try to increase our test coverage to a level we're comfortable
>> with, so for
>> now I'm stuck with writing less-than-ideal tests for less-than-
>> ideal code.
> I realize it's been a few days and apologize for the late response,
> but I just saw this. I hate to be the guy on the mailing list saying
> "you shouldn't be trying to do what you're trying to do," but that's
> sort of where I'm headed. I hope it's helpful anyway.
> When adopting a codebase that wasn't developed test-driven, I'd
> strongly recommend focusing on Rails-style functional tests rather
> than introducing mock-based testing of the current design. The biggest
> downside to mocking is that it ties you to certain interactions
> between objects. When you're using it to determine what those
> interactions should be, that's ok. When you already know you're not
> happy with the way those interactions work and intend to clean them
> up, what you really need is tests that give you a safety net to enable
> refactoring (a green bar that you can keep green as you improve the
> design). Mock-based tests aren't likely to give you that. Rather
> they're probably going to mean that as you skinny down your
> controllers, you'll have to change everything in at least two places
> instead of just one, and meanwhile the suite won't tell you whether
> things are still working.
> Mock-based tests are a useful design tool, and can (in some cases) be
> useful documentation of design, but they don't usually make for a good
> regression suite. All three of those are important when developing
> from scratch. But when taking on legacy code whose design you intend
> to change, the first two goals are off the table. The third is better
> served with higher-level tests.
> It's definitely worth your time to read the 12-page version of Michael
> Feathers' Working Effectively With Legacy Code.
> I hope that wasn't too obnoxious.
> mocha-developer mailing list
> mocha-developer at rubyforge.org
More information about the mocha-developer