我需要为我的iPhone应用程序获取代码覆盖率。
我如何在Xcode 4中获取代码覆盖率?
我需要为我的iPhone应用程序获取代码覆盖率。
我如何在Xcode 4中获取代码覆盖率?
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
参考网站
这里是一些与Xcode相关的网站,涵盖了单元测试和代码覆盖率。我找不到一个好的例子,希望这个能帮助其他人。
如果你想要从你的代码覆盖率生成HTML(一旦你生成了你的.gcda文件),你可以安装lcov
并使用以下命令:
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"
}