0% found this document useful (0 votes)
492 views8 pages

SonarQube Swift Code Coverage Setup

The document discusses how to set up SonarQube to generate code coverage reports for Swift projects on macOS. It outlines the necessary system requirements and prerequisites like JDK, SonarQube, SonarQube Scanner. It also discusses installing additional tools like xcpretty, SwiftLint, Tailor, Slather and Lizard. The document provides steps to download and configure the SonarQube plugin for Swift and configure a sample Xcode project properties file. It describes how to launch an analysis to generate coverage reports that can be viewed on the SonarQube dashboard.

Uploaded by

Huynh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
492 views8 pages

SonarQube Swift Code Coverage Setup

The document discusses how to set up SonarQube to generate code coverage reports for Swift projects on macOS. It outlines the necessary system requirements and prerequisites like JDK, SonarQube, SonarQube Scanner. It also discusses installing additional tools like xcpretty, SwiftLint, Tailor, Slather and Lizard. The document provides steps to download and configure the SonarQube plugin for Swift and configure a sample Xcode project properties file. It describes how to launch an analysis to generate coverage reports that can be viewed on the SonarQube dashboard.

Uploaded by

Huynh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

Code Coverage Reports in SonarQube for Swift on


macOS
Laxman Sahni Follow
Jul 17, 2018 · 4 min read

System requirements
To install and run SonarQube, your development environment must meet these
minimum requirements:

Operating Systems: macOS Sierra 10.13.4 (64-bit)

Disk Space: 1.17 GB (does not include disk space for IDE/tools).

Prerequisites

JDK 1.8
Download JDK 1.8 installer ➜ Move to Applications folder

Get the SonarQube


1. Download the following installation bundle to get the latest stable release of the
SonarQube:

SonarQube 6.7.4

2. Extract the file in the desired location, e.g. ~/Downloads through macOS built-in
extracting tool/unzip CLI in terminal/third-party extracting tools

sudo chmod 777 ~/Downloads/sonarqube-6.7.4/

[Link] 1/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

3. Start the SonarQube server:

~/Downloads/sonarqube-6.7.4/bin/macosx-universal-64/[Link] console

Exceptions like

Encountered an error running main:


[Link]: ~/Downloads/sonarqube-
6.7.4/temp/conf/es/[Link]

Exception of wrapper

may occur, delete contents of temp folder to fix it.

sudo rm -rf temp/*

SonarQube Scanner
1. Download the following installation bundle to get the latest stable release of the
SonarQube Scanner:

2. Expand the downloaded file into the directory of your choice. We’ll refer to it as
<install_directory> in the next steps. I used ~/Downloads .
[Link] 2/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

3. Update the global settings to point to your SonarQube server by editing


<install_directory>/conf/[Link] :

#----- Default SonarQube server

#[Link]=[Link]

SonarQube Server URL in [Link]

4. Add the <install_directory>/bin directory to your path.

<install_directory>/bin in PATH

5. You can verify your installation by opening a new shell and executing the command
sonar-scanner -h . You should get output like this:

usage: sonar-scanner [options]

Options:

-D,--define <arg> Define property

-h,--help Display help information

-v,--version Display version information

-X,--debug Produce execution debug output

xcpretty

gem install xcpretty


[Link] 3/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

SwiftLint (HomeBrew installed) and

brew install swiftlint

Version 0.26.0 or above.

Tailor

brew install tailor

Version 0.11.1 or above.

slather

gem install slather

Version 2.4.0 or above.

slather version

lizard

sudo pip install lizard

SonarQube Plugin for Swift


Download the plugin binary into the $SONARQUBE_HOME/extensions/plugins
directory

[Link] 4/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

plugin binary in $SONARQUBE_HOME/extensions/plugins folder

Copy [Link] somewhere in your PATH. I copied it under


~/Downloads/sonar-scanner-3.2.0.1227-macosx/bin which is in PATH.

Restart the SonarQube server.

Configuration (once per project)


Copy [Link] in your Xcode project root folder (along your
.xcodeproj file)

Edit the [Link] file to match your Xcode iOS project

[Link]

# must be unique in a given SonarQube instance

[Link]=CodeSample:CodingAssessmentApp

[Link]=CodingAssessmentApp

[Link]=1.0

# Project description

[Link]=Coding Assessment App

# Path to source directories

[Link] 5/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

[Link]=CodingAssessmentApp

# Path to test directories (comment if no test)

[Link]=CodingAssessmentAppTests

# Destination Simulator to run surefire

# As string expected in destination argument of xcodebuild command

# Example = [Link]=platform=iOS Simulator,name=iPhone


6,OS=9.2

[Link]=platform=iOS Simulator,name=iPhone 8,OS=11.4

# Xcode project configuration (.xcodeproj)

# and use the later to specify which project(s) to include in the


analysis (comma separated list)

# Specify either xcodeproj or xcodeproj + xcworkspace

[Link]=[Link]

[Link]=[Link]

# Specify your appname.

# This will be something like "myApp"

# Use when basename is different from targeted scheme.

# Or when slather fails with 'No product binary found'

# [Link]=myApp

# Scheme to build your application

[Link]=CodingAssessmentApp

# Configuration to use for your scheme. if you do not specify that


the default will be Debug

[Link]=Debug

# Encoding of the source code. Default is default system encoding

#[Link]=UTF-8

[Link] 6/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

# Paths to exclude from coverage report (surefire, 3rd party


libraries etc.)

# [Link]=pattern1,pattern2

[Link]=.*Tests.*

Launching an analysis
Run the [Link] script from your Xcode project root folder. If you error run-

[Link]: Permission denied ,

Permission denied

Run

chmod +x [Link]

from path of directory of [Link]

Swift Coverage Results

Open browser and navigate to URL [Link] You should see your project in
dashboard.

SonarQube Dashboard

Click on the project to see coverage report.

[Link] 7/8
3/21/2020 Code Coverage Reports in SonarQube for Swift on macOS

Where to Go From Here?


You can generate code coverage reports in Xcode with a Ruby gem Slather.

As always, any feedback is appreciated, so feel free to comment down here or reach out on
twitter — and, as always,

iOS Sonarqube Swift Xcode Macos

About Help Legal

[Link] 8/8

You might also like