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

标签 xcode swift unit-testing

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

这是我到目前为止尝试过的:

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

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

有没有人能够成功地将 @testable import 与 Watch Extension 一起使用?这是我应该能做的事吗?任何帮助将不胜感激。

最佳答案

来自 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 测试框架提出了类似的问题,其中谈到缺乏对 watch kit 扩展测试的支持。看看:https://github.com/Quick/Quick/issues/273 .

关于xcode - @testable 在 Swift 单元测试中导入 Watch Extension 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32071229/

相关文章:

swift - 显示帮助文本以了解 Swift 中函数的功能

iphone - 如何在 xcode 4.2.1 控制台窗口中显示日志消息

objective-c - Objective C : Version of JSON library I'm compiling in present in another library I'm linking in via . a,如何解决冲突?

javascript - react 应用程序 : Jest encountered an unexpected token

c# - NHibernate 可查询单元测试

ios - 我有 UIViewController。而UIView里面如何独立检测触摸?

ios - 不活动时从 UINavigationBar 中删除 UISearchController

ios - 在两个嵌套子类中调用 super.viewDidLoad() 时,我遇到了 Swift 的无限循环

json - 在 Swift 4 中合并一个 Realm 和 Codable 类

C# 在控制台应用程序中嵌入测试代码