Re: Dos and don'ts in C++ unit testing?
kevin cline wrote:
On Feb 16, 7:59 am, Francis Glassborow <fran...@robinton.demon.co.uk>
wrote:
In article <1171546178.649654.103...@a34g2000cwb.googlegroups.com>,
James Kanze <james.ka...@gmail.com> writes
What the OP said, "code a little, test a lot" made me think it meant
you couldn't write 100 lines without spending a long time testing them.
There is another way f viewing that injunction.
Write a little code
test it
add a little more code
test it
add a little more code
test it
etc.
I prefer to:
write a little test
code until all tests pass
write another test
code until all tests pass
...
The art is in figuring out what to test next.
Don't the requirement specifications tell you that?
The real art is figuring out how to write a test which will fail
if the code doesn't meet the requirement specifications. Some
things are easy: after push_back() on an empty vector, size()
should return 1, etc. Others are considerably more difficult:
threading issues come to mind. (I, and a lot of other people,
I'm sure, would be very interested if you know how to write a
test case for libstdc++ bug no. 21334, for example.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
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! ]