@testable在Swift单元测试中导入Watch Extension模块

时间:2015-08-18 11:32:07

标签: xcode swift unit-testing

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

这是我迄今为止所做的尝试:

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

我当然能够通过将所需文件添加到测试目标来成功进行单元测试,但感觉这不应该是必要的。

是否有人能够成功使用@testable import观看分机?这是能够做到的事情吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

来自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和Nimble测试框架打开了一个类似的问题,该框架讨论了对手表套件扩展测试缺乏支持的问题。看看:https://github.com/Quick/Quick/issues/273