Since I’m working on two projects at the moment (both written in C#), and since both of them will end up as games (hopefully), I’ve decided I needed something else to wash away the taste of gameplay code and graphics code and physics code and whatever else kind of code a single game developer must write. So I’ve decided to write my own testing framework for C++! Why?! why not?!
Actually as far as the “why not” question goes I can give many reasons why not (and you, yes YOU, can probably give some more) but heck, this is my time and I want to try it. Let’s see how far I get into it before my eyes go cross 😛
As a first disclaimer I would like to say that I have already started this project a couple of times before just to test (hee hee, see what I did there) the water. As another disclaimer I would also like to mention that I’ve used and am using the wonderfully wonderful UnitTest++ and so am more than a little influenced by it. Having said that, “Test Drum” will not be a copy/paste affair but another approach to that same basic concept.
As I’ve mentioned just passing the framework’s name is ‘Test Drum’. Don’t ask me why since I’ve got no idea.
With that in mind let’s put down some ground rules;
Test Drum is designed to be a portable, lightweight and fast framework for writing tests in C++
So, what’s a test?
A test [in the framework] is any function that contains some expectations in it.
Next, what exactly is an expectation?
Expectations are code slices that test specific conditions on input data; the expectation code should throw a specialized exception (ExpectationFailed) if any of its conditions are not met.
And finally the idea of the TestContext.
A TestContext is a mapping between a name and a 'Test' function. A TestContext is executed in order to run its testing function.
I think that with these three basic ideas I can start writing the framework and later begin iteration and refinement. Already I know that I’m missing basic concepts such as timed tests, test fixtures and test suites. But those I’m happy to add on later once the groundwork is done.
This post is almost done but before I go I want set the corner stone of this framework. Namely, the actual test function, which is in fact nothing more than a function pointer.
typedef void (*Test)();
Well, that’s it for today.
“I may take a holiday in Spain, leave my wings behind me…”