Xctest - Preprocessor Macro

Is it possible to have a macro defined in the target parameters (testing) or in the test .pch file so that it is transmitted to the entire application?
Or is there any macro that is already available for verification (from the code) if we run the test?

eg:

#if TEST=1 // do something #else // do something else #endif 

The reason I want this is to skip some code, claims, etc. during testing (without the need to change #define in the main .pch application every time I run tests).

Thanks.

+6
source share
1 answer

It looks like you can do it very much like Objective-C. The fast compiler accepts the -D switch. To adapt this to testing, I defined a Literal that I wanted to use only in the settings of the test target assembly.

Instruction:

 Build settings for the Test Target -> Swift Compiler Custom Flags -> -DTEST (yes, including the -D prefix) 

Includes this code:

 // Objective-C and Swift #if TEST // Test only code version code #else // App only code #endif 

I found a solution in this article to switch to fast .

+3
source

Source: https://habr.com/ru/post/970997/


All Articles