gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:13 25 4
gpt4 key购买 nike

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

@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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com