How do I get code coverage for Xcode for my Objective-C app?
I need code coverage for my iPhone app.
How do I开发者_运维问答 get code coverage for Xcode 4?
These steps will help.
Create a new build configuration (‘Coverage’), duplicated from the ‘Debug’ configuration.
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”
Compile application with Coverage mode.
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
- http://atastypixel.com/blog/unit-testing-and-coverage-with-xcode/
- http://milesdennis.blogspot.co.uk/2011/04/code-coverage-in-xcode-4.html
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"
}
精彩评论