Optimal strategy for including Catch2 tests?

We’re trying to include Catch2 tests. This was my intended strategy (MacOS, XCode / AppCode):

  1. Create new folder source/tests.
  2. Add catch.hpp and tests.cpp to folder.
  3. Create new target tests.
  4. Set header search paths for tests to mimic those of other plugin targets.
  5. tests.cpp:
#include "catch.hpp"
#include <JuceHeader.h>
#include "project_module_to_test.cpp"

... Tests ...
  1. Create build config for tests target.
  2. Build and run.

Unfortunately this gives an error: No global header file was included!. This references JuceHeader.h which suggests silencing the error using #define JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED.
Attempted fix: Add this to the top of tests.cpp.
Result: Lots of linker errors.

At this point I notice that the plugin targets include (in build phases) the JUCE implementation files from JUCE Library Code as source.
Attempted fix: Add these files to the source for the tests target.
Result: Lots more errors including (mysteriously) the return of the initial No global header file error.

At this point I decide that there is something going way, way, way over my head.

Is this a completely misguided way of configuring Catch2 tests for JUCE or is there something small I’m missing?


1 Like

Did you ever find a solution to this? I’ve seen this issue both trying to make XCTest and Catch2 work with JUCE.

We use Catch2 with a JUCE CMake based project, which works well, but it was not completely straightforeard to set up. See Setting up a Catch2 Test target with CMake

1 Like