4

I am writing unit tests for an app for iPhone using objective c. I want to use some variable only when compiling for test case for example

#ifdef UNIT_TESTING 
@synthesize requestFinished, networkAvailable;//etc
#endif

now where should I define UNIT_TESTING that when I compile for unit tests it should enter this code block.... otherwise should go past it....

Asad Khan
  • 11,469
  • 13
  • 44
  • 59

1 Answers1

3

Define it in the “Preprocessor Macros” build setting in each of your targets—especially the one where you want that macro defined, the unit test bundle target.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • What if the project I want to write unit tests for depends on a static library which I need to use these macros in? The ifdef is never defined since the library is already compiled, no? – Genericrich Apr 08 '11 at 15:39
  • @Genericrich: Right. You would need to define the macros in the library's target when building the library. If you need to use the macros in both places, put them in a header and import that from the prefix headers of both targets. – Peter Hosey Apr 08 '11 at 19:50