Testing VST3 plugin with Catch2, Frut, CMake and CLion

I recently discovered the awesome Frut project and have used it to convert my Projucer project to CMake. I use CLion with the generated CMakeLists.txt file (which then handles all the build details with Xcode in the background using the default CLion toolchain).

I would also like to migrate my unit tests to Catch2 and set up a build target for them in CMake/CLion but I’m having trouble figuring out how to do this (I’m new to both Juce and CMake, and not terribly experienced with C++ either).

So far, I have tried adding a file to the project with the following contents:

// CatchTest.cpp
#include "../External/Catch/catch.hpp"

    REQUIRE(1 == 1);

I am able to set up a new target and run the test by appending this line to the to the CMakeLists.txt file:

add_executable(tests Source/CatchTest.cpp)

So far so good. But the build fails as soon as I include Juce library files in my tests (the included Juce files cannot be found). I could of course try to fix this but I don’t think I’m on the right track here. I think that “circumventing” the Frut generated build for testing is probably just asking for trouble down the road.

I see from other posts on the forum that calling Catch::Session::run() from the main function conditionally based on preprocessor flags might be a viable approach - but since my project is a plugin library there is no main function, so I’m not really sure how to go about doing that…

I wonder if there might be a way to hook into the Standalone plugin “wrapper” (or roll your own)?

1 Like

Hi @rasmus,

Thanks for using FRUT! I’m always very glad to see that it really helps people building JUCE projects.

You’re not the first one to try to combine an Audio Plug-in project with a Catch2 test runner. You can read more about it in that issue on GitHub: https://github.com/McMartin/FRUT/issues/490

If you have any questions, feel free to ask them on the GitHub issue, here or via PM.

Thank you for the quick reply - seems to be just what I’m looking for. If I had realized you were behind FRUT I would would have bought you a beer when we met at ADC (we did the quiz together). Maybe next year :slight_smile:

Works like a charm… awesome!


I’m planning to write more documentation for FRUT and add tutorials/recipes. This type of setup will definitely have to be covered.