ios 测试目标 X 遇到错误(提前意外退出,操作从未完成引导 - 不会尝试重新启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34990175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:38:32  来源:igfitidea点击:

Test target X encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted

iosunit-testingxcode7ocmock

提问by Varun Mehta

I have started working with OCMockto write test cases for the existing project that I have integrated in my project workspace. After following all the steps mentioned in this link.

我已经开始OCMock为我已经集成到我的项目工作区中的现有项目编写测试用例。按照此链接中提到的所有步骤操作后。

When I first executed my test case it's giving the error above. I searched it and tried following some of the solutions like creating new target, restarting Xcodebut it didn't help me out. Any idea?

当我第一次执行我的测试用例时,它给出了上面的错误。我搜索了它并尝试遵循一些解决方案,例如创建新目标重新启动 Xcode,但它没有帮助我。任何的想法?

回答by onmyway133

I have my notes and demo applications for both Cocoapods and Carthage here https://github.com/onmyway133/TestTarget

我在这里有我的 Cocoapods 和 Carthage 的笔记和演示应用程序https://github.com/onmyway133/TestTarget

  • Make sure all frameworks are linked to the Test targets
  • Configure Runpath Search Pathsto point to $(FRAMEWORK_SEARCH_PATHS)
  • 确保所有框架都链接到测试目标
  • 配置Runpath Search Paths指向$(FRAMEWORK_SEARCH_PATHS)

More info

更多信息

回答by Rados?aw Ci?ciwa

I'm using carthage and problem for me was searching for dependencies in a test target. Fix:

我正在使用迦太基,问题是在测试目标中搜索依赖项。使固定:

Add $(PROJECT_DIR)/Carthage/Build/iOSto Runpath Search Paths

添加$(PROJECT_DIR)/Carthage/Build/iOSRunpath Search Paths

You can find reference here: Carthage issue

你可以在这里找到参考:迦太基问题

回答by hujunfeng

There might another solution, if you are using CocoaPods and the UI test target is embedded inside the app target, which is, unfortunately, the case in the default template (pod init).

如果您使用 CocoaPods 并且 UI 测试目标嵌入在应用程序目标中,那么可能还有另一种解决方案,不幸的是,默认模板 ( pod init)就是这种情况。

Try move the UI test target out of the app targetas follows:

尝试将 UI 测试目标移出 app 目标,如下所示:

from:

从:

platform :ios, '11.0'
use_frameworks!

target 'MyApp' do
  # Pods for MyApp

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing

  end
end

to:

到:

platform :ios, '11.0'
use_frameworks!

# Pods shared between MyApp and MyAppUITests    

target 'MyApp' do
    # Pods for MyApp only

end

target 'MyAppUITests' do
    # Pods for testing

end

Credit goes to SpacyRicochet in this issue thread: https://github.com/CocoaPods/CocoaPods/issues/4752#issuecomment-305101269

在此问题线程中归功于 SpacyRicochet:https: //github.com/CocoaPods/CocoaPods/issues/4752#issuecomment-305101269

回答by leizeQ

My solution was to add a "Copy File phase" to my test target. There I set destination to Frameworks and added my framework with the + sign.

我的解决方案是向我的测试目标添加一个“复制文件阶段”。在那里,我将目的地设置为 Frameworks,并用 + 号添加了我的框架。

回答by Lubbo

Just to share my experience about this error:

只是分享我对这个错误的经验:

I'm using fastlane + cocoapods.

我正在使用 fastlane + cocoapods。

I have a workspace with 2 dynamic frameworks:

我有一个带有 2 个动态框架的工作区:

  • A.framework
  • B.framework
  • A.框架
  • B.框架

Dependencies:

依赖项:

  • A depends by AFNetworking using cocoapods
  • B depends by A
  • A 依赖于 AFNetworking 使用 cocoapods
  • B 取决于 A

Dependency are defined in the Podfile.

Podfile 中定义了依赖关系。

The error was raised executing framework B tests.

该错误是在执行框架 B 测试时引发的。

In my case the problem was related to the missing dependency to AFNetworking in B.framework target.

在我的情况下,问题与 B.framework 目标中缺少对 AFNetworking 的依赖有关。

Adding a pod dependency to AFNetworking in B.framework in Podfile, all was resolved.

在 Podfile 的 B.framework 中向 AFNetworking 添加一个 pod 依赖,一切都解决了。

So even if the target B is compiling successfully, AFNetworking was not embedded into the B test app and the simulator wasn't able to run B test app raising this "very meaningful" (*)error.

因此,即使目标 B 编译成功,AFNetworking 也没有嵌入到 B 测试应用程序中,模拟器也无法运行 B 测试应用程序,从而引发这个“非常有意义”的 (*)错误。

(*) thanks to Apple for this!

(*) 感谢 Apple 为此!

回答by FeltMarker

In my case there was nothing wrong with linked files. The Simulator was kind of stuck at the message that the app triggered, like: "App name would like to send you notifications". Pressed OK and the next time my XCTests worked fine.

就我而言,链接文件没有任何问题。模拟器有点卡在应用程序触发的消息上,例如:“应用程序名称想要向您发送通知”。按确定,下次我的 XCTests 工作正常。

回答by Mihriban Minaz

In my case Build Active Architecture Only was set to YES.

在我的情况下,仅构建活动架构被设置为是。

In project and targets : Build Settings -> Architectures -> Build Active Architecture Only should be NO instead of YES

在项目和目标中:Build Settings -> Architectures -> Build Active Architecture Only 应该是 NO 而不是 YES

回答by Yitzchak

My case was special. I used 2 files as test classes. one worked perfectly and the other had that error.
Both link against the same framework.

我的情况很特殊。我使用了 2 个文件作为测试类。一个工作完美,另一个有那个错误。
两者都针对同一个框架链接。

Solution

解决方案

CLEAR DERIVED DATA

Window=> Projects=> Delete(at your project)

清除派生数据

窗口=>项目=>删除(在您的项目中)

Good luck and happy testing!

祝你好运,测试愉快!

回答by possen

Wow, I wasted a lot of time on this, my test bundle had the "Host Application" to my application selected. Other test bundles did not.

哇,我浪费了很多时间,我的测试包选择了我的应用程序的“主机应用程序”。其他测试包没有。

I expect this solution may not be the right solution for every situation, but my tests were mainly to test the dynamic library and it did not really need a Host Application to run. I was getting the above error, turning this off allowed me to run the tests without getting that error and the breakpoints worked. I was running MacOS but it probably does similar for other environments. I expect this solution may not be the right solution for every situation, but my tests were mainly to test the dynamic library and it did not really need a Host Application to run.

我希望这个解决方案可能不是每种情况的正确解决方案,但我的测试主要是测试动态库,它并不真正需要运行主机应用程序。我遇到了上述错误,关闭它允许我运行测试而不会出现该错误并且断点起作用。我正在运行 MacOS,但它可能对其他环境也有类似的作用。我希望这个解决方案可能不是每种情况的正确解决方案,但我的测试主要是为了测试动态库,它并不真正需要运行主机应用程序。

On the test bundle Go to General -> Testing -> Set "Host Application" to None.

在测试包上转到常规 -> 测试 -> 将“主机应用程序”设置为无。

回答by Ben Thomas

In my case I had not added a Run Script phase for the Quick and Nimble libraries which I integrated using Carthage.

就我而言,我没有为使用 Carthage 集成的 Quick 和 Nimble 库添加运行脚本阶段。