2007年2月19日星期一

UnitTest++ : An Excellent C++ Unit Test Framework

There are enormous c++ unit test framework such as CppUnit, TUT, Boost.Test, etc.

I've been using CppUnit for a long time and have a taste of TUT and Boost.Test.

Recently, I come across UnitTest++ which caught my eyes by several lines of demo code.

UnitTest++ is the one that is most simple and intuitive to use and at the mean while a full featured C++ unit test framework.

Here is a sample of how to write a test suite in UnitTest++.

SUITE(SampleTestSuite)

{

TEST(Test1){ CHECK(true); }

TEST(Test2){ CHECK(false); }

TEST(Test3){ CHECK(true); }

}

It looks quite simple and intuitive compared with CppUnit's test cases.

As a full featured c++ test framework it supports exception check and time constraint check as well.

You can get out of box visual studio integration with using UnitTest++ as it generates a visual studio friendly test report that can enable you to locate the fail tests by a single click.

UnitTest C++ increases the productivity compared with CppUnit and frees us greatly from dummy codes that always make us uncomfortable and irritating.

Here is the link to UnitTest++: http://unittest-cpp.sourceforge.net/UnitTest++.html

PS:

Physical design of C++ is really an big issue. A a poor one will surfer you with long compilation and linkage which will turn unit test and continuous integration into unenjoyable experience. Nevertheless, abandon them because of lacking of patient will probably turn the project into a nightmare. Fortunately, we have some practitioners that share their experience with us. Large Scale C++ Design is the book definitely to be read.