April 30, 2006 - Mocking a Singleton

Over on the TDD mailing list there is a thread about mocking a singleton. There are a few good suggestions given but the best answer (imho) is that provided by Michael Hill:
Mocking a singleton is relatively easy.

To begin with, singleton's are all alone in the world; don't be afraid to point this out. Also, most singletons are created, get this, not even in a factory, but merely in a factory method. Finally there is the point that they are little more than dressed-up globals, and IME experience cause more heartache than they're worth. You can point to the many nasty screeds about singletons there are out on the net. All in all, mocking it shouldn't be too hard. A word: if your singleton has unusually large body parts, stoop to insulting that. Sometimes, to be kind, you have to be cruel.

Posted by Jeffrey Fredrick at April 30, 2006 01:59 PM


Trackback Pings

TrackBack URL for this entry:
http://www.developertesting.com/mt/mt-tb.cgi/211

Listed below are links to weblogs that reference Mocking a Singleton:

» *rofl* from Software is too expensive to build cheaply...
Wot Jeffrey said. I'll never be afraid to mock a singleton again.... [Read More]

Tracked on April 30, 2006 04:48 PM

» mocking a singleton from silk and spinach
Some metaphorical terms - such as the names of the GoF design patterns - are so deeply ingrained in our daily work that we get a small shock when we're reminded of the term's origins [Read More]

Tracked on May 4, 2006 12:44 PM


Comments

I posted a reaction to this on my blog, but the trackback reported "Ping 'http://www.developertesting.com/mt/mt-tb.cgi/211' failed: HTTP error: 403 Throttled" - whatever that means! Anyhow, my post is at http://silkandspinach.net/blog/2006/05/mocking_a_singl_1.html

Posted by: kevin rutherford on May 1, 2006 03:50 AM