C++ Unit Testing Framework
I’ve dusted off my C++ unit testing framework as it’s been a bit underfeatured for use on a couple projects I’ve been working on.
The fun part is that it’s the ultimate TDD dogfooding project as I’m oscillating between the tests and the framework itself as it evolves.
Frankly I don’t consider what I’m doing to be re-inventing the wheel. Every C++ unit test framework I’ve tried has thwarted me in some way or another; most frequently in the name of making it easy to add a test via macro-magic.
I just don’t care so much about that. I can type. Besides, the result of having ‘the simplest possible add_test line’ is usually a bunch of crap in the test framework that I just cannot in good conscience abide. Hey, if that’s your goal… awesome. Rock on with your bad self.
If I wanted everything to be a one-liner, I wouldn’t be using C++ in the first place.
My real goal with this is to have a framework that’s as rich as reasonable while using standard C++ (requiring a mature compiler. It’s 2009 for chrissakes, you need to support the language) and keeping the framework to a couple (at most) header files. That’s it. There shouldn’t be anything to getting the framework in to place besides:
#include “testfw.h”
and including your test driver shell.
So we’ll see. It’s ambitious of me to try and simplify this down that far I know. But I’ve only got a couple problems left to solve before I’ll have something worth sharing. HOPEfully I’ll maintain the requisite steam to get that out in a few hours. But I’ve an awful lot to work on today.
It’s going to be a bit before it’s got a nice spit-shine on it. But in the meantime…
UPDATE: 7 hours later I have a reasonable TestSuite class. I’m pretty surprised that there are less than 30 unit tests for it which really cover the thing pretty well. I have yet to add recursive suite support (suite of suites.) And I need to templatize my assert functions, they’re stupid the way they are. But it’s more than serviceable at the moment. Definitely not the worst code I’ve ever written.
I’m spent.
Tags: Agile, C++, Programming, TDD, xUnit