Cross Platform C++ Unit Testing

If you're curious about using an easy cross platform unit testing suite for C++, checkout my fork of CxxTest on github(LGPL2.1). Message me on Github if any of the instructions aren't clear.

Writing cross platform C++ is a liberating experience for anyone who has previously had their code tangled up in a particular operating system's helper functions. While working on ESRI's cross platform geometry library, our brilliant lead developer decided we should all be on board with test driven development. As a result he installed CppUnit as a part of our project solution.

After I left ESRI I found myself curious about keeping up my cross platform skills. So I started writing C++ libraries for iOS games with the idea that I would use JNI on Android to resuse my code (this was how ESRI's geometry library was to be used on their mobile platforms when I left). So having a cross platform unit testing solution made sense. I struggled to get CppUnit to work, and my impatience drove me to give CxxTest(LGPL3) a try.

The CxxTest landing page gives a nice summary of why someone might want to use it for testing:

CxxTest is easy to use because it does not require precompiling a CxxTest testing library, it employs no advanced features of C++ (e.g. RTTI) and it supports a very flexible form of test discovery.

So what's the catch? You need to have python installed on your testing machine in order for the cxxtestgen script to scrape relevant info out of you test header files and place it in the main cpp file. But other than python, it's so absurdly simple to setup CxxTest for unit testing that I've been committed to it for a few years now.

In the past I was using a messy pre-build shell script in XCode to execute cxxtestgen unit test prep. But as of yesterday I have fixed up my fork of CxxTest to use a python script as a prebuild step for preparing the unit tests. The same python script works for a Visual Studio setup. Checkout my CxxTest on github for instructions on how to setup your project to use CxxTest with XCode or Visual Studio.

That's all for CxxTest.

Now for a picture of Voltron. He was sort of like a cross platform robot, right? No? Well...whatever, Voltron is a badass. Picture of Voltron