Catch: what symbol can I use to personalize code for unit-testing

74 Views Asked by At

I am using the Catch C++ test framework. I have a separate test-code file, where I have

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include "my_own_headers.h"

TEST_CASE( "test of thisnthat", "[thisnthat]" )
{
   SomeStuff a(42);
 ...

Is there some symbol that Catch defines at build time that I can use it to change my code definition?

An example: Say I have some struct that needs to having some special constructor but only for testing purposes, for some specific test case. I want to be able to use this constructor when I build my test code, but the regular build should not enable this function.

// someheader.h
struct SomeStuff
{
   int someValue;
 #if BUILD_IS_TEST_MODE
   SomeStuff( int a ), someValue(a) {}
 #endif
};

What symbol can I use ?

I had a look on https://github.com/philsquared/Catch/blob/master/docs/configuration.md but couldn't find anything relevant.

0

There are 0 best solutions below