Why doesn't gcov report any lines being covered by my unit tests?

前端 未结 5 1635
暖寄归人
暖寄归人 2021-02-04 06:23

I am using Xcode 3.2 on 10.6, with the shipped version of gcov and default GCC compiler (both version 4.2.1). I have created a dependent Cocoa unit test bundle which is injected

5条回答
  •  独厮守ぢ
    2021-02-04 06:48

    I have been trying to get the Code coverage working for iPhone simulator and always get a 0% coverage. Below are the configuration details and the steps that I have tried.

    Configuration

    Xcode 3.2.5/iOS 4.1 and iOS 4.2/Mac 10.6/GCC 4.2 Application UICatalog

    References

    http://www.cubiclemuses.com/cm/articles/2009/05/14/coverstory-on-the-iphone/

    http://developer.apple.com/library/mac/#qa/qa2007/qa1514.html

    Steps

    • Enable “Generate Test Coverage Files”
    • Enable “Instrument Program Flow”
    • Add “-lgcov” to “Other Linker Flags”
    • UIApplicationExitsOnSuspend flag in Info.plist is set to true

    Result

    I have the .gcda files generated but the coverage always show 0%.

    Settings tried

    1. Changing GCC to 4.0 and 4.2. When I try to change the GCC to 4.0 I get 26 build errors.
    2. Set environment variables:

      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 Optimization set to None (-O0) and unchecked the precompiled prefix header file flag.

提交回复
热议问题