Hey, An advice in the TDD isn't to write code that drive us to employ the Singleton pattern as it imposes itself as a problem in testability. But Singleton pattern is very important and important (Spring DAOs for example are singletons). Why not starting developing the singleton class with fake implementation and start refactoring it to the real implementation, you know, this is the TDD after all? Does this mean that I don't use singleton in my TDD application? Thanks. [ August 06, 2008: Message edited by: John Todd ]
John, Aren't Spring DAO singletons dependency injected? The singleton itself isn't the problem per se. The problem is how to get a reference/interface that isn't a singleton. For example, when you really need a singleton, putting it behind a factory often helps.
TDD also points out that many things that are singletons don't need to be. Some people have "object creation phobia" and make classes singletons when they could easily be normal objects.
I don't always TDD, but I did try TDD'ng a singleton once. It wound up being something that didn't need to be a singleton and I learned not to presume the implementation. Of course, this doesn't apply to all cases.