0

i have the following code in my unit tests:

#ifndef SERVER_TEST
    NSLog(@"\n\n!!!--- YOU ARE RUNNING TESTS IN STUB MODE ---!!!\n\n!!!--- Server Responses will be stubbed ---!!!\n\n");
#else
    NSLog(@"\n\n!!!--- YOU ARE RUNNING TESTS IN LIVE MODE ---!!!\n\n!!!--- Server Responses will be live ---!!!\n\n");
#endif

SERVER_TEST is defined under Build Settings in my Test target's User Defined Settings.

When I run my tests, #ifndef SERVER_TEST always returns True. Any ideas why?

Thanks?

dornad
  • 1,274
  • 3
  • 17
  • 36
  • Have you tried [using a custom configuration](http://www.innovaptor.com/blog/2013/09/02/xcode-preprocessor-macros-for-test-code.html)? – neilco Dec 09 '13 at 18:53
  • No, I haven't. What would be the advantage of using a custom config, compared to Grzegorz's answer? – dornad Dec 09 '13 at 19:02
  • If you wanted to use the same define in your app code for conditionally compiling in, say, custom logging during test runs, a custom config is best of managing that. – neilco Dec 09 '13 at 19:10

1 Answers1

1

You should keep this flag as Preprocessor macro instead of User Defined Settings.

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
  • That worked! Is there any reason why this works, instead of a User Defined Setting? – dornad Dec 09 '13 at 19:01
  • User Defined Settings are more for keeping variable values - you can read them from code by $(VARIABLE NAME). #ifdef is preprocessor macro so it should be used. You can combine them both, and define variable value in UserDefinedSettings and use them in preprocessor macro as $(VARIABLE_FROM_USER_DEFINES). User defined settings are not translated into preprocessor macro automatically, until you define them in macro section. – Grzegorz Krukowski Dec 09 '13 at 19:11