Tests stop working under xcode 8 TEST_HOST error

前端 未结 12 811
暖寄归人
暖寄归人 2020-12-15 15:13

I want to start tests under Xcode 8 and it fail in the beginning. My error is:

Could not determine bundle identifier for MyProjectTest\'s TEST_HOST:

相关标签:
12条回答
  • 2020-12-15 15:57

    Ok figure it out. There is a problem with naming packages. Unfortunatelly there is some issue with Xcode. I was using different Module Names for different Configurations. So go to Project -> Build Settings -> Product Module Name Change name in all configurations for same name without spaces.

    0 讨论(0)
  • 2020-12-15 15:58

    Under Test Target >> Build Setting >> Testing >> Test Host you can see the .app file which should be used for testing.

    For me **.app file name was wrong. And I replaced it with **/Build/Intermediates/CodeCoverage/Products/Debug-iphonesimulator/**.app (check for the .app file present under this directory).

    0 讨论(0)
  • 2020-12-15 16:00

    Quitting Xcode and removing DerivedData folder at fixed the problem for me.

    $ sudo rm -Rf Library/Developer/Xcode/DerivedData
    

    Shame on you, Apple!

    0 讨论(0)
  • 2020-12-15 16:02

    It seems there are several bugs in Xcode8 that can cause this. However I have found a solution for the case where Xcode tries to find the TEST_HOST app within the Intermediates/CodeCoverage/ folder. (I tried all other solutions with the module names etc and it didn't work for me.)

    The issue itself seems to be that Xcode does not even try to build the app before running the tests. However once Xcode is able to find the TEST_HOST in the folder it will rebuild when launching the tests. That's how we can find our way around it.

    Two possible solutions:

    If you don't have to have code coverage: Go to your unit test target's Build Settings and set Enable Code Coverage Support to No and deactivate code coverage in your build scheme's test setting. (Edit scheme, select Test on the left). If you want to run your unit tests and still get that TEST_HOST error message, try building (CMD+B) or running your app. Then you can run your tests without that error. Voilá.

    If you need code coverage: You can follow a certain workaround to get that Intermediates/CodeCoverage/.. folder filled. Once the app is inside Xcode will rebuild for the unit tests as it should, but you need to get it filled once. This is how you do it:

    • In the app and the unit test target select No for "Enable Code Coverage Support"
    • Then in the "General" tab of the unit test target set the test host application to "None"
    • Uncheck "Allow testing Host API"
    • Try to start unit tests. Xcode will now at least try to build. If Xcode gives a build error (sometimes Xcode complains about Cocoapods here in my experience), try building once again.
    • Re-check "Allow testing Host API" again in the Unit Test target
    • Try running the tests again as above. Xcode should complain.
    • Now set the test host to the app.
    • Now the tests should run through. (Until you run a clean, then you'll have to re-do these steps..)

    I know, it's bothersome. But it's the only solution to the problem so far.

    0 讨论(0)
  • 2020-12-15 16:07

    go to xcode Preferences -> location > Derived Data Advance -> select build location Unique

    0 讨论(0)
  • 2020-12-15 16:12

    What I have discovered is that the tests will not run unless you have built and run the same target you are running the tests against on the device/sim you are testing on.

    For example, if I run the tests against target Production, then I would have to build and run the target Production on the device/sim before I can run the tests. If I did not do that, it will give me the same error.

    0 讨论(0)
提交回复
热议问题