Skip to content

Code coverage configuration

Andrii Mamchur edited this page Nov 13, 2013 · 1 revision

1. Install HomeBrew

Homebrew Official Site

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

2. Install lcov

lcov Official Site

brew install lcov

3. Configure JsonLiteObjC build scheme in Xcode

  • JsonLiteObjC project (/platform/ios/JsonLiteObjC.xcodeproj or /platform/macos/JsonLiteObjC.xcodeproj)
  • Open scheme editor Product->Scheme->Edit Scheme... (⌘<)
  • Go to "Test" scheme
  • Open Pre-actions
  • Add "New Run Script Action". This script will reset all execution counts to zero.
cd "${TEMP_FILE_DIR}/Objects-normal/${CURRENT_ARCH}"
if [ -f "/usr/local/bin/lcov" ]; then
/usr/local/bin/lcov -z -d . --rc lcov_branch_coverage=1
fi
  • Open Post-actions
  • Add "New Run Script Action". This script will generate test coverage report.
cd "${TEMP_FILE_DIR}/Objects-normal/${CURRENT_ARCH}"
if [ -f "/usr/local/bin/lcov" ]; then
/usr/local/bin/lcov -c -d . -o coverage_full.info --rc lcov_branch_coverage=1
/usr/local/bin/lcov -r coverage_full.info tests\* -o coverage_no_tests.info --rc lcov_branch_coverage=1
/usr/local/bin/lcov -r coverage_no_tests.info /Applications/Xcode.app/\* -o coverage.info --rc lcov_branch_coverage=1
/usr/local/bin/genhtml coverage.info -o cov --rc lcov_branch_coverage=1
fi

4. Run JsonLiteObjC test

Product->Test or ⌘U

5. Open Delivery Data folder

  • Open Organiser ⇧⌘2
  • Open Projects Tab
  • Select JsonLiteObjC project
  • Click on arrow icon near Delivery Data path
  • Open {Delivery Data}/Build/Intermediates/JsonLiteObjC.build/Debug-iphonesimulator/JsonLiteObjCTests.build/Objects-normal/cov/index.html