Just some days ago I started looking into a unit test framework called check,
and I intend to run the test on c code under Linux.
Now check and some well designed code and some test code can help me to verify
that the basic functionality is correct,
I mean it is quite easy to just look at the variables in and response back and then
decide if a function is correct or not.
But let's say I want to test a dynamic memory structure with a lot off malloc and free,
and it turns out that I can put data in and get correct data back out again.
But that does not prove that I have not broken some memory in the process,
let's say I forgot to free half off the memory and lost the pointers (a classical memleak).
That code would probably pass most of the unit testing.
So now for the question:
is it a good idea to run the entire unit test code with i.e. Valgrind and let him
detect any malloc/free problems? (Or maybe compile in something like Electric Fence?)
It feels like a good idea, but I'm not sure what I'm getting myself into here…..
Update: Thanks Douglas and Jonathan,
it seems like this is a good idea and something I should continue with 🙂
Update: Valgrind is a fun tool, however the first memleaks I found doing this
was in the test framework and not my own code (quite funny though).
So a tip to the rest out there is to verify that the unit test framework that you are using is not leaking, before turning your own code upside down.
An empty test case was all that was needed in my case,
since then nothing but the unit test framework is running.