XCode - Code Coverage?

2019-01-30 15:45发布

I need code coverage for my iphone app.

Can anyone provide detailed information on how to get code coverage for Xcode 4?

Thanks

3条回答
看我几分像从前
2楼-- · 2019-01-30 16:31

I have an entry on my blog which covers this exact topic.

It provides a step-by-step guide on how to enable GCOV in Xcode 4 as well as how to use CoverStory for displaying the results.

查看更多
干净又极端
3楼-- · 2019-01-30 16:37

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"
}
查看更多
三岁会撩人
4楼-- · 2019-01-30 16:42

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

查看更多
登录 后发表回答