如何在iPhone SDK中设置gcov进行代码覆盖率分析?
我最近开始对我为 iPhone 编写的应用程序进行单元测试。我已经掌握了创建自己的测试的基础知识,即使它看起来有点次优。然而,我在使用 gcov 设置代码覆盖率分析时遇到了真正的麻烦。
我按照此处的说明进行操作: http:// www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/,在其他地方重复得非常相似。我尝试过使用 Google 的 Mac 工具箱中的 AppleScript 可以用来执行此操作,以防万一我在 Xcode 中输入错误。
我使用 Apple 的 iPhoneUnitTests 示例 作为基础项目,并且只需运行 Google 的 AppleScript 即可针对 CalcTests 目标进行代码覆盖测试,以获得一个来源良好的自动化示例,说明它不起作用。无论我使用什么场景,我自己的代码,苹果的代码,手动设置正确的变量或让谷歌的AppleScript为我做这件事,一旦测试运行完成,我得到的只是调试控制台中的这些错误:
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcViewController.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/Calculator.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcAppDelegate.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/main.gcda:Skip
The gcda files are not create ,因此我没有什么可分析的。 任何对此的帮助将不胜感激。
I've recently begun unit testing an app I write for the iPhone. I have the basics of creating my own tests down, even if it seems a little sub-optimal. I am, however, having real trouble setting up code coverage analysis using gcov.
I followed the instructions here: http://www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/, which are repeated very similarly in other places. I've tried using Google's AppleScript from their toolbox for Mac to do it just in case I was entering something wrong in Xcode.
I've used Apple's iPhoneUnitTests sample as a base project, and simply running Google's AppleScript to enable code-coverage testing against the CalcTests target to get a well-sourced, automated example of it not working. No matter what scenario I use, my own code, Apple's, manually setting the proper variables or letting Google's AppleScript do it for me, all I get are these errors in the debug console once the tests are finished running:
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcViewController.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/Calculator.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/CalcAppDelegate.gcda:Skip
profiling:/Users:Cannot create directory
profiling:/Users/jpo/Downloads/iPhoneUnitTests/build/iPhoneUnitTests.build/Debug-iphoneos/CalcTesting.build/Objects-normal/armv6/main.gcda:Skip
The gcda files are not created, and thus I have nothing to analyze.
Any help with this would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是这些指南引用了在 iPhone 模拟器中运行代码。因为我正在运行应用程序级别测试,所以我正在进行交叉分析,并且需要遵循 this信息。
然后,我设置环境变量 GCOV_PREFIX 将其转储到应用程序的 Documents 目录中,然后使用 Xcode 中的 Organizer 从设备下载应用程序包,以从 Documents 目录中获取 .gcda 文件。这是相当麻烦的,几乎不适合自动覆盖测试,但考虑到在沙箱中运行和使用仅可用于在设备上测试的类(即 MediaPlayer.framework)的限制,这是我能看到的唯一解决方案。
The solution is that these guides refer to running code in the iPhone simulator. Because I'm running application level tests, I'm cross-profiling and need to follow this information.
I then set the environment variable GCOV_PREFIX to dump it in my application's Documents directory, and then I use the Organizer in Xcode to download my app's package from the device to get the .gcda files out of the Documents directory. This is rather cumbersome and hardly lends itself to automatic coverage testing, but it is the only solution I can see given the constraints of running in a sandbox and using classes that are only available for testing on the device (namely MediaPlayer.framework).