Re: Can use of singletons denote poor project design?




Phlip wrote:
Daniel Parker wrote:

I don't really see how there are any special issues for writing unit
tests for singletons. For example, in Java, DateFormat.getInstance()
returns a default date format, which is a singleton object, there is
one instance of a default date format. Are you suggesting that you
would have difficulty testing whether this object satisfied its
specified properties? Why?

Could you outline a test that changes the format, calls a method that relies
on formatted dates, and test its output is correct?

Changes the format to something other than what is required for the
default format? Why would you want to do that?

Presumably the default format depends on the default locale, so to test
that you could set the default locale and then test that the properties
of the format returned by getInstance() were as required.

Could we then make the test just a tiiiiny bit simpler by taking out the
singleton and passing the date format directly?

Depends what you're testing. The proposed test was for the default
date format. You seem to be testing something else.

To make the test case harder, suppose in System Q the CurrentTime is a
singleton (because, gee, time is a universal constant, so there's only one
of them). Now write a test that depends on a specific date to pass its
assertions.

Huh???

Regards,
Daniel Parker
http://servingxml.sourceforge.net/

.



Relevant Pages

  • Re: Can use of singletons denote poor project design?
    ... Changes the format to something other than what is required for the ... To see if the target function respects the date format! ... singleton (because, gee, time is a universal constant, so there's only ... Who said anything about the DateFormat being a singleton? ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... returns a default date format, which is a singleton object, there is ... Could you outline a test that changes the format, ... I implied my method can illustrate why some of them suck. ...
    (comp.object)
  • Re: Can use of singletons denote poor project design?
    ... relies on formatted dates, and test its output is correct? ... Changes the format to something other than what is required for the ... To see if the target function respects the date format! ... singleton (because, gee, time is a universal constant, so there's only ...
    (comp.object)
  • Re: When is it appropriate to use static methods?
    ... I am using the following format to create my singleton: ... > namespace Company.TWS.BusinessObject ... The normal singleton pattern would have the _twsDS and twsDS ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: does rubys strftime not attempt POSIX-compliance?
    ... it refers to the "POSIX locale concept" and the ruby compliance with it. ... MS> nothing in common with the libc strftime except the name;-) ... I started using this ISO date format next to my signature on forms back in the early eighties. ...
    (comp.lang.ruby)