CocoaPods项目结构,用于使用私有组件进行单元测试 [英] CocoaPods project structure for unit testing with private components

查看:314
本文介绍了CocoaPods项目结构,用于使用私有组件进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CocoaPods用于具有以下结构的项目:

I am using CocoaPods for a project with the following structure:

Example/
Example/PublicUmbrellaHeader.h
Example/PrivateHeaderForComponent1.h
Example/PrivateHeaderForComponent2.h
Example.podspec
Tests/
Tests/Podfile
Tests/Tests/UnitTestForPrivateComponent1.m
Tests/Tests/UnitTestForPrivateComponent2.m



Tests / Podfile



Tests/Podfile

pod 'Example', :path => '../'

这很常见。例如,AFNetworking遵循类似的结构。 的不同之处在于只需要向单元测试公开某些标头。

This is not unusual. For example, AFNetworking follows a similar structure. What is different is the need to expose a certain set of headers only to the unit tests.

但是,我无法弄清楚做到这一点的方法。
以下方法有效,但是从需要在公共 Podspec 上对
进行手术的意义上讲,这并不是很干净。

However, I could not figure out a straightforward way to do this accomplish this. The following method works, but it is not clean in the sense that it requires surgery on the public Podspec.

s.public_header_files = 'Example/PublicUmbrellaHeader.h'
s.default_subspec = 'Public'
s.subspec 'Public'
s.subspec 'Tests' do |ss|
   ss.public_header_files = 'Example/*.h'
end



测试/ podfile



Tests/Podfile

pod 'Example', :path => '../'
pod 'Example/Tests', :path => '../'

有没有更简单的方法?如果不是,是因为我要完成的工作有问题,还是仅因为CocoaPods尚未满足该用例?

Is there a simpler way? If not, is it because there is something wrong with what I am trying to accomplish, or simply because CocoaPods does not cater to this use case yet?

推荐答案

您可以直接在示例项目中修改测试目标,以将专用标头包含在标头搜索路径中。只需进入您的单元测试目标,然后在搜索路径-> 标题搜索路径下,添加:

You can directly modify the test target in your Example project to include the private headers in the Header Search Paths. Just go into your Unit Test target, and under Search Paths -> Header Search Paths, add:

$(inherited) "${PODS_ROOT}/Headers/Private/Example"

在单元测试文件中,您可以包括以下标题:

In your unit test files, you can include the headers like so:

#import "PrivateHeaderForComponent1.h"
#import "PrivateHeaderForComponent2.h"

而不是典型的 #import < Example / PrivateHeaderForComponent1.h>

缺点是您要假设CocoaPods如何布置Pods目录中的文件,但是我宁愿这样做,也不愿更改我的公共podspec文件。

The downside is you're making assumptions about how CocoaPods lays out the files in the Pods directory, but I would rather do that than change my public podspec file.

这篇关于CocoaPods项目结构,用于使用私有组件进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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