swift - 将目标导入单元测试和在目标成员中包含该文件有什么区别?

标签 swift xcode unit-testing

当我编写测试时,我可以:

@testable import TestProduct

以上与将测试文件添加到特定目标有何不同?

enter image description here

最终我的问题是:如果我将我的 unitTests 设为我所有文件的目标...是否等同于:

@testable import TestProduct

如果不是,那有什么区别?

最佳答案

来自Swift docs单元测试目标的访问级别标题下(添加了强调)

When you write an app with a unit test target, the code in your app needs to be made available to that module in order to be tested. By default, only entities marked as open or public are accessible to other modules. However, a unit test target can access any internal entity, if you mark the import declaration for a product module with the @testable attribute and compile that product module with testing enabled.

这些文档说@testable 属性为您的单元测试目标提供对标记为@testable 的模块的所有内部结构的访问。因此,您无需手动将该模块中的单个文件添加到单元测试目标。

The @testable import is typically done on large codebases that did not have any tests yet... because this approach is significantly slower than adding the files you want to test to the test target.

关于swift - 将目标导入单元测试和在目标成员中包含该文件有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51070263/

相关文章:

ios - 如何在 moveRowAt : sourceIndexPath:? 后删除空白部分

iphone - 在 UITableViewCell 中绘制文本

ios - 将 Nsurl 域名转换为我的国家/地区域名

ios - 你如何在 Swift 中编写模拟?

java - 在 AndroidAnnotations SharedPreferences 中模拟链式方法调用

swift - 无法扩展泛型类型,其中占位符是另一个泛型类型

html - 从 iOS 更改 WebKit 中托管的网站的页面

xcode - 界面生成器中的 Tab 键顺序?

java - Vertx HttpClientRequest 处理程序行为测试

swift - 无法识别的选择器发送到实例 0x7f9d19e02870 ISSUE with UIButton