From: Guillaume Marcais Date: 2004-05-08T22:40:00+09:00 Subject: Re: test unit & singleton Thanks to all of you for good suggestions. Guillaume. Le 8 mai 04, � 05:03, Kent Dahl a �crit : > Gennady wrote: >> That's why you want to avoid singletons as much as possible when it >> comes to unit testing. >> In cases I do need singletons, I usually end up with a regular class >> that can be unit tested, and a separate singleton class that simply >> delegates all calls to my actual class. Or something similar. > > Suggestion for something similar, w/o the delegation overhead: > > Move all functionality of the singleton class into a module. Include > that module in two classes, one which also includes Singleton (for > actual use) and one dummy class for testing. Put the code for the > dummy class in the unit tests themselves, so the application code > doesn't accidentally use it for anything. > > require 'singleton' > module RealStuff > # ... > end > class DummyClass > include RealStuff > end > class RealClass > include RealStuff > include Singleton > end > > -- > (\[ Kent Dahl ]/)_ _~_ _____[ http://www.pvv.org/~kentda/ > ]_____/~ > ))\_student_/(( \__d L b__/ Master of Science in Technology ) > ( \__\_�|�_/__/ ) _) Industrial economics and technology management ( > \____/_�_\____/ (____engineering.discipline_=_Computer::Technology___) > >