Unit testing a plugin with Projucer and Xcode

The most straight-forward way to do this would be to add a new “Test” target to the project which could build the test files, link files to be tested, and run as a command-line app or something. But Projucer does not (that I’ve found) let you add new targets, and will overwrite any targets you add to the project manually. So that’s out.

Searching around for a solution, the information is all old and fragmented. “Use cmake”, or “don’t test plugins” or “copy your code into the sample UnitTestRunner project and run it there” or “ifdef out calls to UnitTestRunner (and, I guess, all your test files?) until you want to run”. I’m hoping someone can provide a modern, canonical answer to the question:

What are the best practices when it comes to running unit tests for Projucer-managed audio plugin built in Xcode?

We actually patched the Projucer to add that test target option before we switched to CMake which made all that a bit easier. But customizing the Projucer was not too hard. The only downside is that you have to maintain a fork which might break at any time

1 Like

My honest advice really is “use CMake”.

As you’ve discovered, the Projucer does not allow you to add additional targets. With CMake, you can easily set up unit test targets and you get a test harness to run all your tests and report results (CTest) - it can even run pluginval and auval.

Tests aren’t even the only additional targets I might want to add to a project. I usually also have a target to build my docs via Doxygen, and probably also some benchmarks.