【发布时间】:2011-02-24 06:07:15
【问题描述】:
我一直在尝试让代码覆盖率适用于 iPhone 模拟器,并且始终获得 0% 的覆盖率。以下是我尝试过的配置细节和步骤。
配置
Xcode 3.2.5/iOS 4.1 和 iOS 4.2/Mac 10.6/GCC 4.2 应用 UICatalog
参考文献
http://www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/
http://developer.apple.com/library/mac/#qa/qa2007/qa1514.html
步骤
- 启用“生成测试覆盖文件”
- 启用“仪器程序流程”
- 将“
-lgcov”添加到“其他链接器标志” -
Info.plist 中的
UIApplicationExitsOnSuspend标志设置为 true
结果
我生成了 .gcda 文件,但覆盖率始终显示为 0%。
已尝试设置
将 GCC 更改为 4.0 和 4.2。当我尝试将 GCC 更改为 4.0 时,出现 26 个构建错误。
-
设置环境变量
(const char *prefix = "GCOV_PREFIX"; const char *prefixValue = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] cStringUsingEncoding:NSASCIIStringEncoding]; // This gets the filepath to the app's Documents directory const char *prefixStrip = "GCOV_PREFIX_STRIP"; const char *prefixStripValue = "1"; setenv(prefix, prefixValue, 1); // This sets an environment variable which tells gcov where to put the .gcda files. setenv(prefixStrip, prefixStripValue, 1); // This tells gcov to strip the default prefix, and use the filepath that we just declared.) GCC 优化设置为无 (-O0) 并取消选中预编译前缀头文件标志。
【问题讨论】:
-
我们可以为iphone设备做代码覆盖吗?(即不适用于模拟器)
标签: objective-c xcode code-coverage