17

When I add a test target that needs a host application in order to run Xcode adds targets that are not associated with the application I added.

I have two schemes (internal & production). I want to run tests on our internal application. When I add the internal application as a host I end up with the production target being added to builds and cannot delete it. If I remove the host application this goes away but the tests also fail.

Does anyone know where I'm going wrong?

Steve
  • 921
  • 1
  • 7
  • 18
  • Happening for me in Xcode 7.3 and Xcode 8 beta 6. Sometimes it's the other target in my project that gets added, other times it's a target from a different project in the same workspace. If you try to remove the rogue target from the test scheme, Xcode crashes. When disabling the "Test" checkbox for the target, Xcode says "The target is required for one or more tests in the Test action of this scheme. Disabling the target will also disable those tests.", then the Test action is greyed out. Solution below not working. – funkybro Sep 06 '16 at 12:28
  • Aha! Solution is here! http://stackoverflow.com/a/26360956/64505 – funkybro Sep 06 '16 at 13:50
  • Possible duplicate of [Build target randomly added to Xcode scheme](http://stackoverflow.com/questions/24169392/build-target-randomly-added-to-xcode-scheme) – funkybro Sep 06 '16 at 13:50

1 Answers1

27

We had the same problems, we fixed them with these steps:

  1. in your testing target, go to the tab 'General' and set the hosting application to 'none', then go to 'Build phases' and remove the target dependency on the former hosting target.

  2. (don't know if this step is necessary) go to 'Window'->'Projects', remove Derived Data from the hosting target and close Xcode. Reopen Xcode again, open your project/workspace.

  3. edit your hosting target's scheme, select "Build" on the left and uncheck "Find Implicit Dependencies" - I believe that this function is somewhat buggy.

  4. in your testing target, go to the tab 'General' and set the hosting application back to its previous value, recheck the target depdencies.

Thomas Elstner
  • 271
  • 2
  • 3
  • 1
    Remember while following step 3, if you are using cocoapods , make sure the pods target is right there at the top, the order of build is very important here. Otherwise your project might end up failing to detect the pod header files. – grassyburrito Jan 18 '16 at 16:00
  • What do you mean? Could you attach screenshot? My app after xcode 8 can not be run on simulator - "run" became disabled – wtorsi Oct 04 '16 at 18:28
  • I had added a Cocoa Touch Framework within a project and received the behavior described in OP's post. The first step of this answer did it for me! Thanks Thomas. I'm in Xcode 10.1. – Zach Jan 23 '19 at 00:54
  • This worked for me, but I had to configure the Test section in the Scheme and re-enable the unit test targets.... I agree with the "somewhat buggy" part... It may be, in fact very buggy – eharo2 Apr 16 '20 at 22:04