为什么 Xcode 7 在根本没有单元测试的情况下显示大约 12% 的代码覆盖率?

Why Xcode 7 shows around 12% code coverage when there are no unit tests at all?

我正在 Xcode 中为 iOS 应用开发一个项目,我在 "Edit scheme -> Test" 中启用了 "Gather coverage data"。

我还创建了一个带有空单元测试的测试目标,这是迄今为止整个项目中唯一的一个,现在当我 运行 测试时,我可以看到大约 12% 的代码已被覆盖(该项目在项目中有大约 500 个文件,覆盖率报告中有许多 类 显示为已覆盖。

这怎么可能?我错过了什么吗?

在 wiki 中有 "In computer science, code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite." 我们只有一个测试套件,而且它是空的。

从 Xcode 8 开始,运行 测试实际实例化应用程序。这意味着所有的初始化代码都被执行了。这将在测试覆盖率报告中显示为覆盖代码。