ios - 单元测试 iOS 应用程序扩展

标签 ios swift xcode unit-testing cocoapods

我的 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 import TodayExtension 但我收到架构 x86_64 undefined symbol 的链接错误。

有什么办法可以解决这个问题吗?

完整的错误代码:

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)

编辑:

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

在苹果文档中只有这个信息:

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.

这不是很有帮助

最佳答案

我遇到了同样的问题。根据this answer ,不支持以这种方式进行单元测试扩展。作为解决方法,您可以将要测试的代码提取到框架中,并将其包含在扩展目标和扩展测试目标中。

关于ios - 单元测试 iOS 应用程序扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586158/

相关文章:

ios - UINavigationBar 设置背景,并设置半透明不起作用

ios - Google 登录错误 -4

iphone - 显示 UIImageView 的问题

ios - 从 nib 文件加载 View 之前运行什么方法或命令?

ios - 通过另一个 ViewController 从一个 ViewController 获取数据

ios - 使用 ARKit 和 SCENEKit 定位虚拟 Assets

php - 根据浏览器检测更改PHP包含

ios - 使用 Sprite Kit 在 Swift 中绘制直线,创建多条线

ios - 带麦克风的 Swift iOS 实时音频处理

ios - SceneKit - 向场景添加新的 SCNNode 会导致严重滞后