I am a big fan of unit testing, mainly because I see that it has a very positive effect on the analysis and design process. You program by intention, telling the computer what it should do rather than how to do it. I really enjoy working with JUnit when doing Java, but I have not found any good frameworks for unit testing in C or C++. I tend to implement my own mini-framework over and over again. It is now a kind of idiom that I keep in my C/C++ toolbox, just like I used to have an Enum idiom for Java.
So what is the problem with the current JUnit wanna-be frameworks out there? All the C and C++ frameworks that I have seen so far are bloated. Someone recently pointed me in the direction of a paper called “The Simples Automated Unit Test Framework That Could Possibly Work” by Chuck Allison. I skimmed through the article (not really bothering to read the text) to look for the actual code and realized immediately that it was just another bloated unit test framework for C++. The title kind of provoked me, but also inspired me to publish my small unit test idiom.
I have chosen to call it QUnit. It is under 100 lines of code. It integrates nicely into your development environment, and there are no bells and whistles. The framework is at sourceforge.
To see more about how to use it you should take a look at some slides from a presentation that I gave for some of my colleagues two weeks ago. The talk was about how test-driven development drives the design process. It presents my simple unit test framework/idiom and show how Uncle Bob’s Bowling Game Kata can be implemented in C++ using QUnit.