Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Unit Testing in C++

Reply
Thread Tools

Unit Testing in C++

 
 
James Kanze
Guest
Posts: n/a
 
      06-25-2008
On Jun 25, 5:08 pm, Noah Roberts <(E-Mail Removed)> wrote:
> Ian Collins wrote:
> > Noah Roberts wrote:
> >> earthwormgaz wrote:


> >>> I'd rather not have to change the original source code
> >>> just to accommodate mocking for unit tests. Is that
> >>> actually what most people end up doing?


> >> I try not to but sometimes it's the only way. It certainly
> >> points to strong coupling when you have to trick your
> >> source into allowing a mock, and maybe you want to do
> >> something about that, but sometimes that's just the way it
> >> is.


> > It's seldom if ever the only way. It might be the easy way,
> > bit it is definitely a design smell.


> I never said it wasn't. In legacy code issues (where complete
> product lines where developed and designed without unit
> testing) it can certainly be the only way to get something
> under test. At times like that you absolutely have to cut
> corners or you can be left refactoring HUGE chunks of code
> without the support of unit tests.


That's a different issue. If you're dealing with legacy code,
or even external code (like Solaris, or Linux), then you
sometimes have to resort to mock functions: you may design your
socket wrapper class to support simulating all possible errors,
but Posix didn't take that into consideration when it designed
its socket interface, and if you're going to test your socket
wrapper class, you'll need to provoke all possible error returns
from the system functions---which probably means linking in a
mock library.

The original poster spoke of a problem due to three headers
being in the same directory. IMHO, either the three headers are
so closely related that they form a single unit, or they belong
in different directories. And units should be very loosely
coupled, only depending on lower units in the hierarchy, which
they can "assume" correct and tested. (As I said, you don't
create a mock std::vector.) In an ideal world, of course.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Webinar - Testing the Untestable - Unit Testing Dependencies andLegacy Code (in C++) Avi C Programming 0 06-11-2012 01:55 PM
[ANN] Webinar - Testing the Untestable - Unit Testing Dependenciesand Legacy Code in C++ Avi C++ 0 06-06-2012 11:25 AM
unit-profiling, similar to unit-testing Ulrich Eckhardt Python 6 11-18-2011 02:00 AM
Unit testing errors (testing the platform module) John Maclean Python 1 04-13-2010 02:11 PM
Test::Unit - Ruby Unit Testing Framework Questions Bill Mosteller Ruby 0 10-22-2009 02:02 PM



Advertisments