代码覆盖率 GCov 不适用于 XCode 4.2 和 iOS SDK 5
我一直试图让 GCov 在 Lion 上使用 iOS SDK 5.0 与 Xcode 4.2Build 4D199 配合使用,但没有成功。有人有这样的运气吗?我使用 Google Tools For Mac 进行单元测试,并在 libprofile_rt.dylib 中链接并添加:
"OTHER_CFLAGS[arch=*]" = (
"-ftest-coverage",
"-fprofile-arcs",
"-falign-loops=16",
);
如 Coverstory 页面所示 http://code.google.com/p/coverstory/wiki/UsingCoverstory 但当我发现. -name *.gcda" 我一无所获。我错过了什么?
I've been trying to get GCov working with Xcode 4.2Build 4D199 on Lion with iOS SDK 5.0 to no avail. Has anyone had any luck with this? I'm using Google Tools For Mac for my unit tests and I've linked in libprofile_rt.dylib and added:
"OTHER_CFLAGS[arch=*]" = (
"-ftest-coverage",
"-fprofile-arcs",
"-falign-loops=16",
);
as indicated on the Coverstory page here http://code.google.com/p/coverstory/wiki/UsingCoverstory
But when I find . -name *.gcda" I come up empty. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XCode 4.2 不再支持 GCov 。您会注意到,如果您访问他们的 “手册页”,XCode 4.2 不是下拉列表中的选项。此外,如果你看一下编译,它使用的是“c++”,它链接到 llvm-g++-4.2。他们现在专门使用 Clang/LLVM 工具链(而后者通常使用 gcc 工具链),而不是让您选择直接使用 gcc 工具链。这样做的结果是,在 XCode4 中使用
gcov
进行代码覆盖不再直接可用。这也会影响使用 CMake 绕过 XCode 4 的编译。 第一个链接为您提供有关如何更改项目以使用profile_rt
而不是gcov
的说明。GCov is no longer supported in XCode 4.2. You'll note that if you go their "man page" for it, XCode 4.2 is not an option in the drop down list. Furthermore, if you look at the compile, it's using "c++", which is linked to llvm-g++-4.2. They now exclusively use the Clang/LLVM tool chain (which in turn often makes use of the gcc tool chain) instead of giving you the option of directly using the gcc tool chain. A consequence of this is that doing code coverage in XCode4 with
gcov
is no longer directly available. This also can affect compiles using CMake that bypass XCode 4. That first link gives you instructions on how to change your project to useprofile_rt
instead ofgcov
.如何生成覆盖率测试报告(Xcode 4.5 版本)
cd
到您的 Xcode 项目并输入在您的主目标和 SentestKit 目标上设置以下构建属性,但仅适用于调试配置(展开节点,有 Debug和发布条目):
安装 Xcode 命令行工具:Xcode >首选项>下载>>命令行工具。
在您的主目标中,添加一个“运行脚本”构建阶段来执行
./XcodeCoverage/exportenv.sh
构建您的应用程序,并运行测试。
从 XcodeCoverage 中生成覆盖率报告,输入:
./getcov
完成后,该脚本将启动带有 html 输出的浏览器。
如果未生成报告,请尝试以下操作:
如需更多提示和技巧,请查看 Richard Buckle 的iOS 上的代码覆盖率演讲。
How to generate coverage test reports (Xcode 4.5 edition)
cd
to your Xcode project and typeSet the following build properties on both your main target and your SentestKit target, but only for the Debug configuration (expand the node, there are Debug and Release entries):
Install Xcode command line tools: Xcode > Preferences > Downloads > Command Line Tools.
In your main target, add a “Run Script” build phase to execute
./XcodeCoverage/exportenv.sh
Build your application, and run the tests.
Generate the coverage report from the XcodeCoverage typing:
./getcov
Upon completion, the script will launch a browser with the html output.
If reports are not generated try this:
Then run your application and press Home. This will quit cleanly and generate the gcda files.
For more tips and tricks check the talk Code Coverage on iOS by Richard Buckle.