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,820 of 33,346   
   =?UTF-8?Q?Tobias=20M=C3=BCller?= to Ian Collins   
   Re: Unit Testing Frameworks (was Re: Sin   
   25 Jan 13 09:56:28   
   
   l-september.org> 703cded6   
   From: troplin@bluewin.ch   
      
   Ian Collins  wrote:   
   > That isn't really a good example.  I have a number tests that use a   
   > custom allocator library (mainly for leak checking).  All I do is within   
   > a test, tell it the next allocation should fail.  Admittedly these tests   
   > are primarily for a C code base where DI isn't an option, but the   
   > technique is still sound.   
      
   Ok let me summarize:   
      
   You use link time substitution because you don't want to have the real code   
   around in the test.   
      
   Then you realize that your tests need the real code as well. You cannot use   
   both in parallel, it would cause conflicts.   
      
   You resolve that conflict by creating a new mock that can manually switch   
   between "real" behavior and mock behavior. BTW, how do you implement the   
   "real" behavior if you cannot use the real code?   
      
   So you rely on the fact, that code that needs the "real" behavior can   
   always be cleanly separated from code that you want to use the mock.   
   That may be easy in C, but in C++ it's increasingly difficult especially in   
   the presence of:   
   - nontrivial constructors/destructors/conversion operators   
   - templates   
   And even if it is possible it's still ugly, fragile, error prone, and not   
   thread safe.   
      
   Tobi   
      
      
   --   
         [ 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