【问题标题】:CocoaPods project structure for unit testing with private components使用私有组件进行单元测试的 CocoaPods 项目结构
【发布时间】:2013-12-13 06:38:05
【问题描述】:

我将 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 遵循类似的结构。 的不同之处在于只需要向单元测试公开一组标头。

但是,我想不出一个简单的方法来完成这个。这 以下方法有效,但从需要手术的意义上说它不干净 公众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 还不适合这个用例?

【问题讨论】:

    标签: ios cocoapods project-structure


    【解决方案1】:

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

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

    在您的单元测试文件中,您可以像这样包含标题:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-08
      • 2013-01-04
      • 2020-12-03
      • 2015-11-21
      • 1970-01-01
      • 2022-07-28
      • 2019-09-16
      • 1970-01-01
      相关资源
      最近更新 更多