简体   繁体   English

为什么我永远不想启用可测试性

[英]Why would I ever NOT want to Enable Testability

In ios apps the default behaviour appears to be to fail for Test Compilation. 在ios应用中,默认行为似乎无法通过“测试编译”进行。 瓦特

Why would I want that to be default? 我为什么要默认它? Surely, at worst, I would want Debug to have it enabled? 当然,最糟糕的是,我希望启用Debug吗? What changes does Enabling Testability actually make? 启用可测试性实际上会发生什么变化?

I happened upon this while tracking down another issue. 我在追踪另一个问题时碰巧遇到了这个问题。 But perhaps I can give provide a scenario. 但也许我可以提供一个方案。 Why would you ever not want to enable testability? 为什么您永远不想启用可测试性?

-fvisibility=hidden. -fvisibility =隐藏。

If you want to use the GCC_SYMBOLS_PRIVATE_EXTERN (aka Symbols Hidden By Default), enable testability has higher precedence and will override this. 如果要使用GCC_SYMBOLS_PRIVATE_EXTERN(也称为默认隐藏的符号),则启用可测试性具有更高的优先级,并将覆盖此优先级。

In my case, I have a configuration which is copied from Debug and hence has Enable Testability == YES. 就我而言,我有一个从Debug复制的配置,因此具有Enable Testability == YES。 I have an external static library which was built with -fvisibility=hidden which is used to build one of my own static libs (built with Xcode). 我有一个使用-fvisibility = hidden构建的外部静态库,该库用于构建我自己的静态库之一(使用Xcode构建)。 However when building my debug builds, I get errors such as (I redacted the function names and paths) 但是,在构建调试版本时,会出现诸如以下错误(我编辑了函数名称和路径)

Showing All Messages : Direct access in function ... means the weak symbol cannot be overridden at runtime. 显示所有消息:在函数中直接访问... ...表示弱符号不能在运行时被覆盖。 This was likely caused by different translation units being compiled with different visibility settings. 这可能是由于使用不同的可见性设置编译了不同的翻译单元造成的。

From the Apple doc here: 从此处的Apple文档:

https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/04-writing_tests.html

When you set the Enable Testability build setting to Yes, which is true by default for test builds in new projects, Xcode includes the -enable-testing flag during compilation. 当您将“启用可测试性”构建设置设置为“是”时,对于新项目中的测试构建,默认情况下为true,则Xcode在编译过程中会包含-enable-testing标志。 This makes the Swift entities declared in the compiled module eligible for a higher level of access. 这使得在已编译模块中声明的Swift实体有资格获得更高级别的访问权限。

It would seem that it is also there for Swift accessibility. 似乎它也可以用于Swift辅助功能。 So if you are not using Xcode's testing and Swift, it would also seem like you could do without this. 因此,如果您不使用Xcode的测试和Swift,那么似乎也可以不使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM