代码之家  ›  专栏  ›  技术社区  ›  user23743

为什么gcov没有报告我的单元测试覆盖了任何行?

  •  15
  • user23743  · 技术社区  · 17 年前

    setting up a gcov-instrumented build configuration -基于未启用任何编译器优化的调试配置。

    build/<AppTarget>.build/Gcov-instrumented/<AppTarget>.build/Objects-normal/x86_64/<object>.gcda

    build/<AppTarget>.build/Gcov-instrumented/<AppTarget>.build/Objects-normal/x86_64/<object>.gcno

    5 回复  |  直到 6 年前
        1
  •  10
  •   Quinn Taylor    16 年前

    我偶尔会遇到这个问题。我偶然发现了一段相当长的幸运时光,在我的主要项目中“大部分时间都在工作”。我所说的大部分时间都在工作,是指我能够得到报道,但比10.5更痛苦。例如,为了获得任何更新,我不得不积极删除覆盖文件并重新构建。即使在我“几乎不工作”的状态下,编译器/运行时似乎也不愿意覆盖现有的覆盖率数据文件。

    这能让你得到预期的覆盖率数据吗?

    Cover Story ),我收到这样的警告:

    .gcno

        2
  •  7
  •   user23743 user23743    13 年前

    在Xcode 4.6中,覆盖率报告似乎正常工作。为应用程序目标打开“生成测试覆盖率文件”和“仪器程序流”,运行测试,然后将覆盖率工具指向输出。在里面 ~/Library/Developer/Xcode/Derived Data/<Project>-<hash>/Build/Intermediates/<Target>.build/Debug-iphonesimulator/<Target>.build ;在CoverStory中打开该文件夹会显示我预期的结果。

    This GitHub repository 包含可以自动发现输出并使lcov可视化的脚本;我现在对封面故事很满意。

        3
  •  2
  •   dmaclach    16 年前
        4
  •  0
  •   Peter Hosey    15 年前

    我一直在努力让代码覆盖率适用于iPhone模拟器,并且总是得到0%的覆盖率。下面是我尝试过的配置细节和步骤。

    Xcode 3.2.5/iOS 4.1和iOS 4.2/Mac 10.6/GCC 4.2 应用

    参考文献

    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中的UIApplicationExitsOnSsuspend标志设置为true

    已尝试设置

    1. 将GCC更改为4.0和4.2。当我尝试将GCC更改为4.0时,我收到了26个构建错误。
    2. 设置环境变量:

      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.)
      
    3. GCC优化设置为None(-O0),并取消选中预编译前缀头文件标志。
        5
  •  0
  •   Vanuan tacaswell    15 年前

    当静态库的*.gcno文件被共享库的文件覆盖时,我的覆盖率为0。