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,771 of 33,346   
   Dave Abrahams to All   
   Re: Unit Testing Frameworks (was Re: Sin   
   30 Dec 12 00:31:03   
   
   From: dave@boostpro.com   
      
   on Fri Dec 28 2012, Ian Collins  wrote:   
      
   > 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)   
      
   FWIW, I wasn't talking about testing the singleton, but about testing   
   the components that /use/ the singleton.   
      
   > 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".   
      
   Even if that's true, I don't see how that relates to my points above.   
      
   --   
   Dave Abrahams   
   BoostPro Computing                  Software Development        Training   
   http://www.boostpro.com             Clang/LLVM/EDG Compilers  C++  Boost   
      
      
         [ 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