home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,768 of 33,346   
   Ian Collins to Dave Abrahams   
   Re: Unit Testing Frameworks (was Re: Sin   
   28 Dec 12 18:57:57   
   
   From: ian-news@this.is.invalid   
      
   Dave Abrahams wrote:   
   > on Fri Dec 28 2012, Ian Collins  wrote:   
   >   
   >> Dave Abrahams wrote:   
   >>>   
   >>> A logger singleton is probably not the greatest example for proving   
   >>> this point, because its actions are usually benign and often   
   >>> untested.  However, the use of a singleton may impede or prevent the   
   >>> logger from being replaced for testing purposes, or prevent   
   >>> different loggers from being used for individual tests.   
   >>   
   >> How?   
   >>   
   >> This is the nub of the argument, but nothing posted so far backs up   
   >> the assertion.  The preceding posts all demonstrate the use of   
   >> different loggers.   
   >   
   > It seems self-evident to me, but I'll try to explain anyway.   
   >   
   > * Most singletons are designed not to allow arbitrary lifetime   
   >    management at all, so you can only have one during the life of the   
   >    executable   
   >   
   > * In any case, only one instance of a singleton can exist at a given   
   >    time, by definition   
   >   
   > * Therefore if you have two tests that need to talk to different loggers   
   >    they either must be in separate executables (in the first case) or at   
   >    least can't run in separate threads (in the second case).   
   >   
   > What am I missing?   
      
   Unit tests normally (in the case of a singleton, nearly always) use   
   mocks for foreign objects required by the tests.  I think that was clear   
   from the examples in this thread using a type called "MyLogger".   
      
   --   
   Ian Collins   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca