Re: Dos and don'ts in C++ unit testing?
On Mar 7, 2:13 am, "Phlip" <phlip2...@gmail.com> wrote:
James Kanze wrote:
If you know the next line of code to write (and if you already have a
test harness), then you must perforce be able to think of a simple
test that will fail if the code is not there.
That's simply false. I often write things like:
boost::mutex::scoped_lock lock( someMutex ) ;
when I know that I cannot possibly write a test case which will
fail on my machine (a single processor Sparc), usually, cannot
possibly write a test case guaranteed to fail anywhere. (But I
know that the code will fail, once in a blue moon, without the
My code is also full of asserts of things I know can't happen.
They're there to protect the maintenance programmer: they
document expectations, and even if he misses the documentation,
the code won't get very far if he doesn't meet them.
I also write documentation in the form of comments. How does
your test test that they are correct?
The test needn't be
perfect - bad code could pass it. You simply write the test to confirm
you need the code, then write the code to pass the test. Repeat in
This is simply bad engineering. You write code because it is
necessary to solve a problem. Whether you can test for the
problem or not. Parts of that problem space are almost by
definition not testable: how do you test the maintainability,
for example. Other parts are typically not ammendable to
reasonable tests: if you run a test long enough, you might even
be able to check some of the threading issues, but a test which
runs for several years just won't cut it (and I've seen
threading issues which will only cause a problem about once a
year, or less, under intensive use).
James Kanze (GABI Software) email:firstname.lastname@example.org
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
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]