在 iOS 逻辑测试中使用 CocoaPods 时找不到库 [英] Libraries not found when using CocoaPods with iOS logic tests

查看:28
本文介绍了在 iOS 逻辑测试中使用 CocoaPods 时找不到库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对我的项目中的类编写一些 iOS 逻辑测试,这些类使用了我的 podspec 中某些库的功能.我正在使用 Xcode 中提供的标准单元测试包(虽然不是应用程序测试,只是单元测试).

I am trying to write some iOS logic tests against classes in my project that use functionality from some of the libraries in my podspec. I am using the standard unit test bundle provided in Xcode (although not Application Tests, just Unit Tests).

例如,我使用 Magical Record,并且在我的 podspec 中链接了该库.它存在于我工作区的 Pods 项目中,并且在应用程序在模拟器或设备上运行时按预期工作.但是,当我尝试将使用 Magical Record 的对象链接到测试时,出现链接器错误,指出它无法从 Magical Record 找到选择器.我已经尝试在我的逻辑测试包中更新我的 HEADER_SEARCH_PATH,甚至将它硬编码到 CocoaPods 创建的 headers 目录,但没有运气.

For example, I use Magical Record, and I have that library linked in my podspec. It is present in the Pods project in my workspace, and works as expected when the app is running in the simulator or on the device. When I try to link to the test the object that uses Magical Record, however, I get a linker error stating that it can't find the selectors from Magical Record. I have tried updating my HEADER_SEARCH_PATH in my logic testing bundle, even hard coding it to the headers directory created by CocoaPods, but no luck.

我可以毫无问题地对不使用 CocoaPods 库的类运行单元测试.

I can run unit tests against classes that do not use CocoaPods libraries with no problem.

我这样做错了吗?我应该做其他事情让编译器看到 CocoaPods 库吗?

Am I going about this wrong? Should I be doing something else to get the compiler to see the CocoaPods libraries?

推荐答案

我通过查看我的应用程序的主要目标如何从 CocoaPods 库接收设置来解决这个问题.CocoaPods 包含一个名为 Pods.xcconfig 的 .xcconfig 文件.此文件包含所有标头搜索路径.

I figured this one out by looking at how the main target of my app was receiving settings from the CocoaPods library. CocoaPods includes an .xcconfig file named Pods.xcconfig. This file contains all of the header search paths.

如果您在项目导航器中查看您的项目并单击信息选项卡,您将看到您的构建配置列在顶部部分.如果您打开不同配置的显示三角形,您将看到主要目标下列出的 Pod.我必须点击下拉菜单并将 Pod 添加到逻辑测试目标.

If you look at your project in the project navigator and click the Info tab, you will see your build configurations listed on the top section. If you open the disclosure triangle for your different configurations, you will see Pods listed under your main target. I had to click the drop down and add Pods to the logic test target as well.

我还必须从我的主要目标复制 $(inherited)${PODS_HEADERS_SEARCH_PATHS} 的设置,并将它们复制到构建设置下的逻辑测试目标/HEADER_SEARCH_PATHS.

I also had to copy the settings of $(inherited) and ${PODS_HEADERS_SEARCH_PATHS} from my main target and copy them over to the logic test target under Build Settings/HEADER_SEARCH_PATHS.

最后,我必须在 Link Binary with Libraries 构建阶段为我的逻辑测试目标添加 libPods.a.

Finally, I had to add libPods.a in the Link Binary with Libraries build phase for my logic tests target.

希望这能帮助其他人.

这篇关于在 iOS 逻辑测试中使用 CocoaPods 时找不到库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆