CocoaPods项目结构,用于使用私有组件进行unit testing
我正在使用CocoaPods进行具有以下结构的项目:
Example/ Example/PublicUmbrellaHeader.h Example/PrivateHeaderForComponent1.h Example/PrivateHeaderForComponent2.h Example.podspec Tests/ Tests/Podfile Tests/Tests/UnitTestForPrivateComponent1.m Tests/Tests/UnitTestForPrivateComponent2.m
测试/ Podfile
pod 'Example', :path => '../'
这并不罕见。 例如,AFNetworking遵循类似的结构。 不同的是需要将一组标题仅暴露给unit testing。
但是,我无法找到一种直接的方法来实现这一目标。 以下方法有效,但从公共Podspec
需要手术的意义上讲它并不干净。
Example.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
pod 'Example', :path => '../' pod 'Example/Tests', :path => '../'
有更简单的方法吗? 如果没有,是因为我想要完成的事情有什么问题,或者仅仅因为CocoaPods不适合这个用例呢?
您可以直接修改Example项目中的测试目标,以在Header搜索路径中包含私有标头。 只需进入unit testing目标,在搜索路径 – > 页眉搜索路径下 ,添加:
$(inherited) "${PODS_ROOT}/Headers/Private/Example"
在unit testing文件中,您可以包含如下标题:
#import "PrivateHeaderForComponent1.h" #import "PrivateHeaderForComponent2.h"
而不是典型的#import
缺点是您正在假设CocoaPods如何布置Pods目录中的文件,但我宁愿这样做也不要改变我的公共podspec文件。