This document discusses how to generate code coverage reports in Xcode. It explains what code coverage is and how to enable it in Xcode. It then introduces Slather, a Ruby gem that can convert Xcode's code coverage format to other formats. It provides instructions for installing Slather and using it to generate HTML and Cobertura XML reports from Xcode test runs. It includes examples of running tests with xcodebuild and using Slather to create reports.
SQL Database Design For Developers at php[tek] 2024
Generate Code Coverage Reports in Xcode
1. How to Generate Code Coverage Reports in
Xcode
Allan Shih
JULY 28TH, 2017
2. Agenda
• What is Code Coverage
• How to Enable Code Coverage in Xcode
• Slather
• Generating Reports
• Demo
• Reference
3. What is Code Coverage
Code Coverage is a measurement of how
many functions / lines / statements of your
code are executed while the automated
tests are running.
4. Code Coverage in Xcode
During the WWDC 2015 keynote, Apple
announced that Xcode 7 would introduce
support of code coverage for our beloved
Swift.
5. How to Enable Code Coverage in Xcode
1. Use Xcode 7
2. Access the scheme setting
3. In the Test tab
4. Enable the Gather coverage data setting
available on your scheme settings window
12. Convert Coverage Data
Before Xcode 7, We can generate coverage
data in the gcov format and use LTP Gcov
Extension (lcov) together with a custom
script to integrate the coverage data into CI
service.
13. Convert Coverage Data
• After Xcode 7, Xcode uses LLVM to
generate code coverage data.
• Slather, a great little Ruby tool that can
convert coverage data to various other
formats
14. Support services and formats
• Supports various services and formats,
including Codecov, Coveralls, Travis CI Pro,
TeamCity, Cobertura, static HTML
15. Installation
• Add this line to your application's Gemfile:
– gem 'slather'
– And then execute: bundle
• Install the gem
– gem install slather
16. Basic Usage
• Running tests with xcodebuild
• Create a coverage report as static html pages
17. Running tests with xcodebuild
xcodebuild
-configuration Debug
-project PlayformSDK.xcodeproj
-scheme PlayformSDK
-enableCodeCoverage YES
-destination 'platform=iOS Simulator,name=iPhone 7'
ONLY_ACTIVE_ARCH=YES
test
18. Running tests with xcodebuild and workspace
xcodebuild
-configuration Debug
-workspace PlayformTVOS.xcworkspace
-scheme PlayformTVOS
-enableCodeCoverage YES
-destination 'platform=tvOS Simulator,name=Apple TV 1080p'
ONLY_ACTIVE_ARCH=YES
test
19. Create a coverage report as static html pages
slather coverage
--html
--output-directory reports
--scheme PlayformSDK
PlayformSDK.xcodeproj
20. Create a coverage report with workspace
slather coverage
--html
--output-directory reports
--scheme PlayformTVOS
--workspace PlayformTVOS.xcworkspace
PlayformTVOS.xcodeproj
28. Next - Code Coverage with Jenkins
• To share an Xcode project’s scheme
• Set up Jenkins
• Create a shell script to Perform Integrations
– Running tests with xcodebuild
– Convert the coverage data to xml and html report
29. Reference
• Continuous Integration and Code Coverage in Xcode
• How to Generate Code Coverage Reports in Xcode
• Continuous iOS Code Coverage With Jenkins and Slather
• Slather
• OCUnit2JUnit