Tutorial :cross platform unit testing in C


I'm starting a new project and decided that I should give this unit testing thing that everybody keeps talking about a try.

The project is a set of C libraries (so no UI or user interaction testing is necessary) and aimed at being cross platform, with Linux, FreeBSD and Windows being my first priority and OS X planned once the first release is out the door (assuming I can get a hold of a machine running OS X to test on).

Does anybody have any experience or recommendations for a good C unit testing framework that easily works across multiple platforms?


I used to use CUnit which I liked. Also google have open sourced their C++ unit testing framework.


Back when I was writing C code all of my unit tests were ad-hoc, no framework involved, so I can't recommend any of these, but you may want to look at the list of C/C++ unit testing tools at http://www.opensourcetesting.org/unit_c.php.


I started with minunit then evolved it to suit my requirements. Rather than having support for test suites from a testing framework, I just use make to build and run different executables, each with a dozen or so related tests in them. So now I've about 250 lines of macros, mainly for printing out different types or doing string or memory comparison, and that's enough for now.


I've grown quite partial to tap (scroll down near the bottom) because its easy to drop in place. It stands for "test anything protocol". I don't think you'd hit many portability issues with it if using compilers released in the last 5 years, but I've only tried it with gcc / glibc.


I use my own unit testing framework CUnitWin32 for embedded C stuff. My host dev environment is Win32 so the framework that is available on-line is for Windows only. However, I did port it to Linux as well, so if the framework works for you, drop me a comment here and we'll work out a way to get your the Linux version.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »