Endama
Endama

Reputation: 743

Automated Testing and Xcode Configuration File to specify API Target

So I am writing Automated tests that run from the command line to test the UI of my iOS application. I have the bash script working that cleans and builds the project and runs my UI Automated tests.

The problem is, I want the command-line script to be able to change a C Flag in my Xcode project that determines which server I am pointed at for my application. For example:

./run-test -target "Debug-Server"

will change the value of the C-Flag SERVER_ADDRESS to DEBUG_SERVER while:

./run-test -target "QA-Server"

changes the value of the C-Flag SERVER_ADDRESS to QA_SERVER

In order to do this, I plan to create a .xcconfig file that is fed into xcodebuild that will set the C Flags in my code to point to the correct server. Something like this:

xcodebuild -target <TARGET_NAME> -configuration Debug-QA.xcconfig -sdk "$DEVICE_SLUG""$CURRENT_SDK" DSTROOT=. clean build

I really am not familiar at all with .xcconfig files so I have a few questions about them.

  1. Do I have to describe every build setting in my .xcconfig file? Or is there some kind of "default" value that Xcode uses?
  2. Is there a better way of doing this?

Upvotes: 3

Views: 950

Answers (1)

Endama
Endama

Reputation: 743

I figured it out, used a combination of .xcconfig and #ifdef statements:

In the configuration file where I declare the server:

#ifdef USE_DEV
#define SERVER_ADDRESS   DEV_SERVER_ADDRESS   //USED IN AUTOMATED TESTING DEBUG SERVERS

#elif defined USE_QA
#define SERVER_ADDRESS   QA_ADDRESSS          //USED IN AUTOMATED TESTING STAGING SERVERS 

#elif defined USE_LIVE
#define SERVER_ADDRESS   LIVE_SERVER_ADDRESS  //USED IN AUTOMATED TESTING LIVE SERVERS

#else
#define SERVER_ADDRESS   DEV_SERVER_ADDRESS   //DEFAULT VALUES
#endif

I then used three .xcconfig files which state the following:

dev.xcconfig:

GCC_PREPROCESSOR_DEFINITIONS = USE_DEV

QA.xcconfig:

GCC_PREPROCESSOR_DEFINITIONS = USE_QA

LIVE.xcconfig:

GCC_PREPROCESSOR_DEFINITIONS = USE_LIVE

Upvotes: 3

Related Questions