SONAR Qube Integration — iOS Projects (with Code Coverage)

XCode 11 & above

Static Code Analysis tool — SONAR — is being used by Organisations for tracking Code Reliability, Security, Maintainability & Technical Debt. We have Code Coverage synced on SONAr as well.

For iOS Projects, we can have this sync working by following below steps -

  • Download SONAR SCANNER at machine
  • Create file and place that at project root
  • Add below key-values in properties file -
  • Open Terminal & change directory to your project
  • Execute below command

You are DONE!! you can now check your SONAR Qube Portal for analysis details.

Code Coverage Sync

Xcode has its own file format for code coverage — xcresult.

SONAR doesn’t understand this file structure and this file needs to be mapped as per SONAR syntax. We need to convert xcresult file into required format.

  • Create a file and paste below code
  • Execute Tests using below command (Note that derivedDataPath has been defined to make sure xcresult file is generated at defined location)
  • After executing Tests with Code Coverage enabled, execute below command
  • Above command will generate a file named “sonarqube-generic-coverage.xml” at project root.
  • Make below entry in sonar-properties file
  • Execute SONAR using sonar-scanner again as stated above

You’ll see that Code Coverage has also been synced and now you can see uncovered lines in SONAR portal.

I design modular development & templates for better coding practices, robustness, scaling & reusability for development inline with automation.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store