Re: Unit Testing in C++
On Jun 25, 7:01 am, Ian Collins <ian-n...@hotmail.com> wrote:
James Kanze wrote:
On Jun 24, 5:53 pm, Noah Roberts <u...@example.net> wrote:
This often involves mock objects.
Not if your code is well designed and well engineered. It
sometimes involves mock objects, but I find that with good
design, it this isn't the case that frequently.
Something is wrong here, I agree 100% with James on a unit
test issue!
It looks like the OP is facing a common problem caused by
adding unit tests after the fact, rather than designing them
in form day -1.
I'd express it a bit differently: if adding unit tests after the
fact does cause problems, then it's often (but not always) a
symptom of poor design and unnecessary coupling. Which in the
long run, causes problems not just for testing, but for other
things as well.
There is one point that hasn't been mentionned (and I'm pretty
sure you'd agree with me on it): classes which provide low level
services should generally be designed so that higher level code
can use them directly in there tests. Thus, a class which wraps
a socket interface should have a "debug mode" in which test code
(in the client tests) can trigger all possible error conditions.
And the global operator new/operator delete you use in your
tests should provide a mechanism to force an std::bad_alloc at
will (as well as checking for memory leaks, etc.). In other
words, suppliers of low level components should expect clients
to want to unit test, and provide the necessary hooks.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34