How do I get code coverage for Xcode for my Objective-C app?
Asked Answered
A

2

22

I need code coverage for my iPhone app.

How do I get code coverage for Xcode 4?

Acromion answered 1/5, 2011 at 22:51 Comment(4)
Clang/LLVM don’t have support for gcov and don’t provide code coverage capabilities. You might be able to use gcov with GCC depending on whether your program builds with GCC. See this bug report at LLVM and consider filing a feature request radar, too.Jenness
You have set UIApplicationExitsOnSusspend to YES in your info.plistAcromion
@Bavarious: According to your bugreport, clang supports coverage now?Moretta
@Joh Yup, nlewycky has added gcov support in LLVM trunk, and nope, the bug report isn’t mine. ;-) I’m not sure if/when Apple will make it available via Xcode, though. You might be able to use it if you build LLVM locally.Jenness
H
9

These steps will help.

  1. Create a new build configuration (‘Coverage’), duplicated from the ‘Debug’ configuration.

  2. Open up build settings for the main target, make sure your new configuration is selected, and:

    Enable “Generate Test Coverage Files”
    Enable “Instrument Program Flow”
    Add “-lgcov” to “Other Linker Flags”
    
  3. Compile application with Coverage mode.

  4. Check .gcno files from your application bundle folder.

    Coverage-iphonesimulator/applicationname.build/Objects-normal

    open .gcno files with CoverStory. Download CoverStory from
    http://code.google.com/p/coverstory/downloads/list

Reference Sites

Hesler answered 2/5, 2011 at 7:41 Comment(0)
P
3

I couldn't find a good example of this, so hopefully this will help someone else.

If you want to generate HTML from your code coverage (once you get your .gcda files generated), you can install lcov and use these commands:

function generate-codecoverage-html() {
    if [[ $1 == "-h" || ! $# -eq 2 ]]; then
        echo "    usage: $0 path/to/codecoverage/dir/ path/to/htmldir/"
        return
    fi

    timestamp=$(date)
    tmpfile="/tmp/codecoverage.info-$date"
    lcov --no-checksum --directory "$1" --capture --output-file "$tmpfile"
    genhtml --output-directory  "$2" "$tmpfile"
}
Parting answered 21/9, 2012 at 16:39 Comment(2)
where is 'lcov'?Critical
found it; github.com/linux-test-project/lcov , referenced in github.com/jonreid/XcodeCoverageCritical

© 2022 - 2024 — McMap. All rights reserved.