加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

单元测试iOS应用扩展

发布时间:2020-12-14 19:20:16 所属栏目:百科 来源:网络整理
导读:我的iOS应用有多个扩展程序: 今天延期 siri扩展 imessage扩展 我还创建了共享公共代码的框架.我的问题是我想要一个单元测试目标,它将测试所有扩展.我的Podfile看起来像这样: target 'MyApp' do pod 'MyFramework',:path = './MyFramework' target 'MyAppTe
我的iOS应用有多个扩展程序:

>今天延期
> siri扩展
> imessage扩展

我还创建了共享公共代码的框架.我的问题是我想要一个单元测试目标,它将测试所有扩展.我的Podfile看起来像这样:

target 'MyApp' do
   pod 'MyFramework',:path => './MyFramework'
     target 'MyAppTests' do
       inherit! :search_paths
     end
 end

abstract_target 'Extensions' do
  pod 'MyFramework',:path => './MyFramework'
  target 'TodayExtension'
  target 'SiriExtension'
  target 'iMessageExtension'
  target 'ExtensionsTests'
end

如您所见,我创建了ExtensionsTests目标,但我不知道如何继承所有扩展的搜索路径.我也试过用
@testable导入TodayExtension但我得到了架构x86_64的未定义符号的链接错误.

我有什么想法可以解决这个问题?

完整的错误代码:

Undefined symbols for architecture x86_64:
  "type metadata accessor for TodayExtension.LoadingView",referenced from:
      ExtensionTests.LoadingViewTests.setUp () -> () in LoadingViewTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

编辑:

我认为这个问题很普遍:我如何测试任何扩展代码?我创建了单个视图项目,今天添加了扩展,我无法扩展代码.

在apple docs中只有这些信息:

To test an app extension using the Xcode testing framework (that is,
the XCTest APIs),write tests that exercise the extension code using
your containing app as the host environment. To learn more about
testing,see Testing with Xcode.

这不是很有帮助

解决方法

Apple文档的引用是完全正确的.

To test an app extension using the Xcode testing framework (that is,the XCTest APIs),write tests that exercise the extension code using your containing app as the host environment. To learn more about testing,see Testing with Xcode.

你可能陷入陷阱,我发现自己陷入了很多陷阱:单元测试应该测试功能的“单位”.不要测试“单位”中的每个小辅助函数,而是测试公共函数.框架也是如此.仅针对公共功能编写测试.如果您测试的是更多,那么您在编写测试时会花费太多时间.

您可以创建一个单元测试目标,并选择您的主应用程序作为“待测试的目标”然后在测试文件中加载扩展名就像主机应用程序一样,并测试主机应用程序将使用的交互正确返回.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读