Unit Tests: Custom Projucer Target for Audio Plugins

After some more evaluation (and distraction by other work) we finally decided to go with the modded Projucer instead of a cmake solution. For anyone interested, here is a patch that can be applied to JUCE 5.4.3, with the following changes:

JUCE_543_AudioPlugin_GoogleTestTarget.zip (917.6 KB)

  • Added GoogleTestConsoleApp as a new plugin format in the projucer
  • Added googletest sources to the juce_audio_plugin_client module
  • adjusted XCode and Visual Studio exporters to
    • assign all files with a basename ending on _gtest to the GoogleTestConsoleApp target and exclude them from the other targets
    • link the SharedCode target to the GoogleTestConsoleApp target so that a full plugin can be instantiated as part of the tests
    • define the JUCE_CURRENT_TARGET_IS_GTEST_CONSOLE_APP preprocessor macro in the corresponding build target

Now the workflow is like this:

  1. Create an audio plugin project with the modded projucer
  2. Set the checkmark for the GoogleTestConsoleApp target
  3. Add your test source code as cpp files to any folder in the project, but use this naming scheme: <mytestfile>_gtest.cpp. Those files will only be built as part of the GoogleTestConsoleApp target and will be excluded from the other build targets (this follows the convention for the other special targets like VST, AU, etc where the file ending also determines to which target the file will be added). The google test headers will be included with the juce header when this target is built.
  4. save the project and open it in XCode or Visual Studio
  5. you will find that there is now a new build target that builds a console app. This app will run all tests that were found in your *_gtest.cpp sourcecode files. Under Visual Studio, they will also appear in the test explorer panel so you can run tests individually.

I’m open to feedback on this. It would be great if something like this could be part of JUCE natively. It would certainly lower the setup hassles and make it easier to develop test driven plugins with JUCE.

1 Like