Unit testing Openframeworks projects in Xcode with Catch

Catch is a very simple automated test framework for C++ (and Objective-C).  It’s packaged up as a single header.

This guide shows how to set it up for unit testing an openFrameworks project (0.8.4) in Xcode (5.1.1 on OSX 10.8.5).

Open the OF project (SampleProject from now on) in Xcode and follow the instructions in this great tutorial to add a target for testing.

Now, comes the tricky part:

If you try to compile the testing scheme (don’t forget to activate it! – Fig. 0)

Fig. 0 - Activate TestXXX scheme

Fig. 0 – Activate TestXXX scheme

you’ll get an error because the compiler can’t find a library named libfmodex.dylib for that target.  This library needs to be in the same folder than the executable.  That might be SampleProject/bin/  (your newly created TestSampleProject executable should be sitting next to the SampleProject.app bundle and the data/ folder).  The library can be found inside the application bundle of your  project (SampleProject.app).  To get it, open the package contents by right-clicking (or CTRL+click) on the app bundle and choosing Show Package Contents (Fig. 1)

Browse package contents

Fig. 1 - Browse package contents

You’ll find the library in Contents/MacOS/.  Copy it to the location of your TestSampleProject executable folder (SampleProject/bin/) (Fig. 2)

Fig. 2 - The libfmodex.dylib library next to the executable

Fig. 2 - The libfmodex.dylib library next to the executable

 

That being done,  now you need to change the build settings of the Testing scheme in Xcode.  Click on the project and select the TestSampleProject target (Figs. 3 and 4)

Click on the project and target dropdown list

Fig. 3 – Click on the project and target dropdown list

Select TestSampleProject target

Fig. 4 – Select TestSampleProject target

Finally, set the C++ Dialect to Compiler Default and the C++ Standard Library to libstdc++ (GNU standard library  (Fig. 5)

Fig. 5 - Settings for C++ Dialect and C++ Standard Library

Fig. 5 – Settings for C++ Dialect and C++ Standard Library

That’s it.  Populate your TestFolder with .cpp test files and fill’em up with unit tests!