Re: [dwm] C unit testing

From: Szabolcs Nagy <>
Date: Tue, 10 Mar 2009 10:29:54 +0100

On 3/10/09, Anselm R Garbe <> wrote:
> 2009/3/10 Richard Pöttler <>:
>> I just wanted to ask you guys if you could recommend me a tool to
>> unit test my C code. So far I only found CUnit, Check and CuTest but
>> haven't dug into any of them. Do you have any suggestions?
> #include <assert.h>

i see two immediate problems with assert:
1) one may want a message per failed test (to have a list) instead of abort
2) eg. equality checks are very common, but with assert
    assert(x == y && "important eq check")
the values of x,y are not shown in case of failure (which are
important for understanding what went wrong)

one can easily define helper macros like
eq_assert(x, y, message)

i'm not sure whether it is convenient to use or not.
unfortunately there are many special cases, like the eq_assert, when
it is possible to print useful additional messages without repetitive
printfs and
most test "frameworks" exploit these situations to provide a more
complete tool, but they are difficult to use in my experience.
Received on Tue Mar 10 2009 - 09:29:54 UTC

This archive was generated by hypermail 2.2.0 : Tue Mar 10 2009 - 09:36:06 UTC