Wednesday, August 29, 2007

C unit testing framework

There was some complaints about how much boilerplate code was required in CUnit, and how much cleaner c++ tests were. I found it a bit absurd to use c++ unit test framework to test c-code just because of the boilerplate code, so I whipped up some wrapper around CUnit to avoid the boilerplate code, and poured in some gcc-extensions and linker tricks to make it work nicely. It is available for download here. So now you have the choice between portable tests or lots of boilerplate code.

A test suite looks like this:

INIT("Stupid testsuite") {
return 0;

return 0;

TEST(test_1, "Test case 1") {
CU_ASSERT(0 == 10 - 10);

TEST(test_2, "Test case 2") {
int i = 10 + 20;
CU_ASSERT(i == 30);

Oh, did I mention that each testsuite is put in a separate shared object which the runner loads using libdl?

Labels: , ,


Post a Comment

<< Home