Tests targets in Projucer?


Hey everyone,
I’m new to Juce and I really love it so far. I’m developing on OS X, but my stuff needs to build/run on multiple platforms and as such I manage my project with Projucer.
Now, I’d like to add some tests to my code base, but haven’t figured out how to best do this. Until now (i.e. before using Juce), I’d build the SUT as a static library that would then be used by say the “main startup” source file (e.g. console app), as well as by the tests, where a test runner would be its own executable that would run all the tests: so I end up with two artifacts: the shippable “thing” and the “test suite” as a console app.
Not sure if this approach even makes sense here, but I have trouble seeing what is the best way of going about this in Projucer so that I can keep my project portable to different development environment. Any pointers?


So here is what I have done in the meantime:

int main(int argc, char *argv[]) {

    int failures = 0;
        fprintf(stderr, "DEBUG BUILD, Running tests first\n");
        UnitTestRunner unitTestRunner;
        for (int i = 0; i < unitTestRunner.getNumResults(); ++i) {
            failures += unitTestRunner.getResult(i)->failures;

    if (failures > 0) {

    // continue with actual main method as "normal"

I created another group/dir with all my test classes in .cpp files using JUCE’s UnitTest base class.
Some tests do actually take some time to run (e.g. actual time based ones). So not quite sure how pleased I am with this approach, but it certainly results in tests actually being executed!

Any further clues/ideas are very much welcome!


You can also add more macro defines to specific build configurations. For example, in addition to Release and Debug you could also add a “Test” build configuration. To do this, right-click on the Xcode icon (or any other platform’s native project type) in the config tab of the projucer and select “Add a new configuration”. You can then add extra preprocessor definitions in the “Preprocessor definitions” field.


What Continuous Integration server do you use? Many of them allow you to add extra preprocessor definitions in the build configuration.


@fabian Y that sounds like another approach indeed. Given Release has much more optimization, I was kinda looking for a way to be able to run the tests with both setups. I does feel nice to run all tests that often, but feels also kinda wrong to not be able to run some subset of tests only during development.
Maybe a plugin idea for my IDE! :wink:


@jpoag Y, the CI isn’t even the issue really… more the how to integrate tests into the daily dev cycles. But preprocessor seems like the agreed on approach though! Thanks!