Re: Dos and don'ts in C++ unit testing?
Rune Allnor wrote:
I'm a hobby C++ programmer who have reached the point where
strain of testing and debugging code are about to outweigh the
fun and usefulness of my projects.
As is said in most books (e.g. "Pragmatic programmer"), "code a
little, test a lot."
However, this might be very good advice, but how does one go
about actually achieving this?
Take all the time you spend, after coding, in debugging.
Transfer it to time spent, before coding, writing test cases.
Design would be more useful.
You will have lots of time left over.
How does writing the tests before you write the code, rather
than later, change the amount of time spent in debugging. If
you don't design your code, you're going to spend a lot of time
in debugging. If you do, you're going to spend a lot less.
Regardless of when you write the tests.
There are those who call this "test-driven development". Write failing
tests, then write code to pass the tests. This implies you (generally) only
write new code if you can get a test to fail, first, because it's not there.
Which neglects the entire problem of specification.
"test-driven development" is one of those catch words, invented
when there are no other good arguments. The very first thing
you have to do when developing software is to decide what it has
to do---what the requirements specifications are. Then, design.
Only once you've done these two steps can you start writing
And of course, the requirements almost always contain aspects
which are *not* testable. Where I work, for example, it is a
requirement for almost everything I write that it be thread safe
(impossible to test), and understandable by others (even more
impossible to test).
James Kanze (GABI Software) email:email@example.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! ]