【问题标题】:@testable import of Watch Extension module in Swift unit tests@testable 在 Swift 单元测试中导入 Watch Extension 模块
【发布时间】:2015-11-11 07:41:16
【问题描述】:

我最近注意到@testable import 似乎不适用于 Watch Extension 模块。

这是我迄今为止尝试过的:

  • 使用 WatchKit 应用创建一个新的 Xcode 项目并包含单元测试。
  • 打开自动创建的单元测试文件并添加@testable import ProjectName_WatchKit_Extension(确认这是扩展构建设置中正确的模块名称后)。这会产生“没有这样的模块”编译器错误。
  • 确认扩展构建设置中的“启用可测试性”设置为“是”。
  • 更改扩展模块的名称以删除空格

我当然可以通过将所需文件添加到测试目标来成功进行单元测试,但感觉这应该没有必要。

有没有人能够通过手表扩展成功使用@testable import?这是我应该能够做到的吗?任何帮助将不胜感激。

【问题讨论】:

  • 现在有解决办法吗?

标签: xcode swift unit-testing


【解决方案1】:

来自 Instagram 库 IGInterfaceDataTable:https://github.com/facebookarchive/IGInterfaceDataTable/tree/e5565a96c5a71ef7b849920adc34f880cc37dc03#testing

Since WKInterfaceTable objects must be initialized from storyboards, and 
there is no mechanism yet to create a WatchKit storyboard in code, we cannot use 
Xcode unit tests yet.

For now, tests are run manually by executing the ApplicationTests WatchKit 
extension and ensuring that none of the asserts are fired.

这是一个很好的问题,我看到针对 Quick and Nimble 测试框架提出了类似的问题,该框架谈到缺乏对手表套件扩展测试的支持。看一看:https://github.com/Quick/Quick/issues/273.

【讨论】:

    猜你喜欢
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 2015-12-10
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    相关资源
    最近更新 更多