fdsaas
fdsaas

Reputation: 714

Xcode / iOS: Unit Tests, Schemes, and Configurations

My iOS project has five schemes: Local Development, Integration, QA, Demo, and Production. Each scheme uses a differing configuration to control things like network poll frequency, API endpoints, analytics, and so on.

Similarly, we have five corresponding targets: Local Development, Integration, QA, Demo, and Production. Each target has several User-Defined Build Settings, which contain API keys, numeric values for timing, etc.

Our application's Info.plist file uses application variables such as ${SOME_ENDPOINT_URL} to draw in the corresponding User-Defined Build Settings.

To retrieve the variables, I do something like the following:

[[[NSBundle mainBundle] infoDictionary] valueForKey:@"Some Endpoint URL"]

That would correspond to the User-Defined Build Setting, like this:

"Some Endpoint URL" = ${SOME_ENDPOINT_URL}

I am now looking at how to configure the project appropriately to perform unit and logic tests.

To build out the tests to determine if the environments are configured correctly, I'm not certain what the best practice is.

Upvotes: 6

Views: 1341

Answers (1)

Pattrawoot S.
Pattrawoot S.

Reputation: 227

The following are what I do.

Info.plist

  • Create a master Info.plist file
  • Write a run script (Shell Script) for each scheme to generate a environment-specific Info.plist by modifying settings in the master Info.plist (Use PlistBuddy -c)
  • Add the run script to Build Phases (above "Compile Sources")

.h file

  • Define configuration settings in a .h file (e.g. config.h)

    #if defined (CONFIG_FILE) 
    #import CONFIG_FILE
    #endif
    
  • Import config.h in your code

  • Use pre-processor macros for each scheme to select the target .h file.

    -DCONFIG_FILE=local-env-config.h
    

Upvotes: 1

Related Questions