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

查看:322
本文介绍了使用带有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创建的头文件目录中,但没有运气。

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.

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

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.

我还必须复制 $(继承)和我的主目标的 $ {PODS_HEADERS_SEARCH_PATHS} 并将它们复制到Build Settings / 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.

最后,我必须在链接二进制文件中添加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天全站免登陆