Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you create a "superset" target in Xcode?

For the purposes of unit testing I'd like to create an iPhone project target in Xcode that includes all of the release application files, plus some additional files containing code useful for UI unit testing.

I can do this by duplicating the original application target; however, the problem with this is that every time I add a new source file to the app target, I need to also add it to the UnitTestUI target. It's not a big deal, just inconvenient to always remember to add files to both targets.

Is there some way to set up a dependency so that every file added to the original app target is also auto added the unit test target?

like image 799
thrusty Avatar asked Jan 05 '09 02:01

thrusty


1 Answers

In Xcode, you can create targets which have direct dependencies on each other. There are a number of non-product building targets that can help with this in the Other category when adding a new target, depending on how simple or complicated your set-up is. Creating specific targets for running unit tests with a direct dependency on the main project target is very common and is documented by Apple and on a number of blogs.

In your situation, however, you may have to do a lot of tweaking on the new, UI testing target, but once it's set up, it will be very easy to maintain. Not knowing your exact situation, it's impossible to give you a step-by-step answer, but here are the general guidelines (tweak to suit your situation):

  1. Create the copy of your original target since most of your settings will be the same.
  2. Select your new target and open the inspector (⌘I)
  3. Under Direct Dependencies, click the + button and select your main target.
  4. Set up the new target as desired, with extra documentation/source/rules or whatever.

If you prefer dragging and dropping things around, you can also drag your original target (from under the Targets disclosure triangle) into your new target and it will automatically set up the dependency.

Now, select your testing target as the active target and it will always build with those rules. Also, if you add/change source in the main target, it will properly be rebuilt when building your testing target... no need to remember to add a source file to the testing target as well. I suggest taking some time to read the various Xcode docs and playing with a lot of the target templates available... in the long run, it really helps make using the product a lot more efficient. There are a lot of nifty things that can be done fairly easily in Xcode if you know how, even with very large or complex projects.

like image 99
Jason Coco Avatar answered Oct 18 '22 19:10

Jason Coco