2

While developing an iOS application, I am required to run unit & ui tests on a preloaded database. So, I planned to include the DB file preloaded in the App only for DEBUG build as UI/Unit tests will run only with DEBUG build. How can i exclude the DB file from Release build?

Currently I can detect if the host app is running for testing or not using following way,

https://stackoverflow.com/a/33466038/1084174,

but how can exclude and include database.db using this technique?

A little guidance will really be appreciated.

Community
  • 1
  • 1
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

2 Answers2

3

Finally i solve the problem.

  1. Open your project file. At the bottom of the screen click Add Build Setting -> Add User Defined Setting and name it EXCLUDED_SOURCE_FILE_NAMES.

  2. Click the arrow to the left of EXCLUDED_SOURCE_FILE_NAMES to expand it. In the Release configuration for this variable, add libTestFlight.a and any other files you’d like to exclude (separated by spaces).

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

The standard way to do this would be to create a new Target in Xcode to use for debug. You can then use the target selector on files

File targets

Here you can see I have a source file that is included in my main target, but not in my messages extension. This appears in the Utilities pane on the right hand side of the screen. You can achieve the same by including a file in your debug target, but not release (or vice versa).

George Green
  • 4,807
  • 5
  • 31
  • 45
  • I have currently four targets, App, Widget, Tests, UITests, do u mean another target to add? – Sazzad Hissain Khan Mar 10 '17 at 09:54
  • @SazzadHissainKhan I do. Your `App` target will essentially become your release target. I would duplicate this target and call the new one something like `App - Staging`, and then you can switch which files belong to each one. You can then set all sorts of different options and configuration for this version. – George Green Mar 10 '17 at 10:36