Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #8590

Re: c++ compiler

From yatremblay@bel1lin202.(none) (Yannick Tremblay)
Newsgroups comp.lang.c++
Subject Re: c++ compiler
Date 2011-08-09 13:28 +0000
Organization A noiseless patient Spider
Message-ID <j1rcmr$e4d$1@dont-email.me> (permalink)
References <59223312-c2e1-416f-b647-5d0df25bc2b8@f17g2000prf.googlegroups.com> <9a4gl1FfkpU1@mid.individual.net> <4e3d43cf$0$30711$5fc3050@news.tiscali.nl> <j1k35l$uhv$1@news.albasani.net>

Show all headers | View raw


In article <j1k35l$uhv$1@news.albasani.net>, BGB  <cr88192@hotmail.com> wrote:
>
>yep.
>
>unit tests are good at testing that the thing does what it is defined as 
>doing, so one can write out a basic spec, and tests to make sure that 
>behavior is what it is supposed to be (most often, some things are 
>harder to run automated tests on than others).
>
>debuggers are better at finding random errors and edge cases which may 
>not have been adequately tested for, or which may fall outside the scope 
>of its defined behavior, for example:
>what happens when the API is called prior to initialization?
>what happens if the API's Init functions are called during operation or 
>multiple times?
>what happens if NULL is passed in unexpected places?
>...
>
>these things are not normally tested in unit tests, which typically 
>handle defined behavior and use, and not anomalous behavior and 
>use-patterns (for which there may be far more anomalous patterns to test 
>for than to test for defined behavior, but programming errors are often 
>much better at stepping on these edge cases).

Wow!  Ian was a bit tongue-in-cheek with his unit test comments but
you are way off the mark.  Unit tests are absolutely not meant to only
cover normal execution path.  In fact, you will never reach high code
coverage stats if you only unit test the normal success path.  The
proportion of code that exist to handle error is huge.  If you write
it, test it.

You should have a unit test for calling the API prior to
initialisation (assuming your API requires initialisation)
You should have unit tests to verify that calling init more that
once. 
If your interface takes pointers, you should test what happens with
NULL pointers. 
Etc. 

You probably never reach 100% coverage but really, at least try to
cover the basic failure scenarios you listed above. Plus you should
run your unit test in a memory analyser so that leaks and boundary
violation are detected.   

That said, I have nothing against debuggers.  I've even been know to
run through some unit tests in a debuggers :-)

Yannick

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

c++ compiler krishnakanth <kmanivan82@gmail.com> - 2011-08-03 13:34 -0700
  Re: c++ compiler Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-03 17:11 -0400
    Re: c++ compiler "Waldek M." <wm@localhost.localdomain> - 2011-08-04 21:40 +0200
      Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-04 15:06 -0700
      Re: c++ compiler Qi <no@no.no> - 2011-08-05 10:14 +0800
        Re: c++ compiler Miles Bader <miles@gnu.org> - 2011-08-05 15:02 +0900
          Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-05 02:11 -0700
            Re: c++ compiler Miles Bader <miles@gnu.org> - 2011-08-05 18:41 +0900
              Re: c++ compiler Victor Bazarov <v.bazarov@comcast.invalid> - 2011-08-05 07:58 -0400
                Re: c++ compiler "Waldek M." <wm@localhost.localdomain> - 2011-08-05 21:30 +0200
                Re: c++ compiler Ian Collins <ian-news@hotmail.com> - 2011-08-06 09:53 +1200
                Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-05 15:10 -0700
                Re: c++ compiler Ian Collins <ian-news@hotmail.com> - 2011-08-06 10:20 +1200
                Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-05 18:30 -0700
                Re: c++ compiler Ian Collins <ian-news@hotmail.com> - 2011-08-06 15:25 +1200
                Re: c++ compiler Dombo <dombo@disposable.invalid> - 2011-08-06 10:42 +0200
                Re: c++ compiler Ian Collins <ian-news@hotmail.com> - 2011-08-06 21:42 +1200
                Re: c++ compiler Dombo <dombo@disposable.invalid> - 2011-08-06 15:38 +0200
                Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-06 11:58 -0700
                Re: c++ compiler yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2011-08-09 13:28 +0000
                Re: c++ compiler Ian Collins <ian-news@hotmail.com> - 2011-08-07 08:33 +1200
              Re: c++ compiler BGB <cr88192@hotmail.com> - 2011-08-05 12:34 -0700
  Re: c++ compiler "Mel Smith" <med_cutout_syntel@aol.com> - 2011-08-05 15:13 -0600

csiph-web