Re: Dos and don'ts in C++ unit testing?
Mathias Gaunard wrote:
On Feb 14, 3:21 pm, "James Kanze" <james.ka...@gmail.com> wrote:
You need it, in order to validate your process. Obviously, if
the tests find an error, there's something wrong in your process
upstream, which you'll want to address. But in my experience,
if you skip on the testing, things will degenerate upstream, and
you'll end up with very bad code.
That's certainly a laudable goal, but it isn't nearly 100%
possible. What the compiler can't catch, of course, code review
There is difference between testing everytime when writing code and
making a fully fledged review at the end of the development cycle.
I'm not sure what you mean by "testing everytime". As I pointed
out, regression tests are important because regardless of the
principles involved, you're not going to do a full fledged code
review for every one line bug fix. And of course, testing keeps
the reviewers (and everyone else) honest.
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.
It doesn't have to be a long time, but extensive unit tests are
useful. And some units aren't much more than 100 lines
(although a 1000 lines would be more common).
Tests are an important part of the quality process, and cannot
be neglected. That doesn't mean, however, that they are the
entire quality process. You can't effectively test until you
know what to test, and that means e.g. hard requirement
specifications up front; for unit tests, that means a good,
solid design which clearly specifies exactly what each testable
unit is to do. And tests will never replace good, independant
code review---their most important use, in fact, is detecting
errors in the review process. (Note that unit tests are
normally part of the code review---insufficient unit tests can
mean that the code fails the review.)
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! ]