Code coverage for iOS with Azure DevOps and SonarCloud

Hi,
i am working on a project where I would like to use SonarCloud test coverage together with iOS and Azure DevOps.

I will explain my current setup. At the moment SonarCloud works, the only part that does not work is the code coverage.

In Azure we have set a Sonar Cloud Service Connection. I can verify this works.
I have a sonar-project.properties file with the following properties in it:

sonar.language=swift
sonar.projectKey=MyProjectKey
sonar.organization=MyOrganization
sonar.projectName=MyProjectName
sonar.projectVersion=9.0.0
sonar.sources=MyProjectSources
sonar.sourceEncoding=UTF-8
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

I also have a yaml file for the Azure DevOps pipeline with the following code:

trigger:
  branches:
    include:
      - develop
      - feature/

pool:
  vmImage: 'macOS-11'

stages:
  - stage: Setup
    jobs:
    - job: sonarcloud
      steps:
      - task: SonarCloudPrepare@1
        displayName: 'Prepare analysis on SonarCloud'
        inputs:
          SonarCloud: sonarCloudServiceConnection
          organization: myOrganization
          scannerMode: CLI
            
      - task: SonarCloudAnalyze@1
        displayName: 'Run Code Analysis'
          
      - task: SonarCloudPublish@1
        inputs:
          pollingTimeoutSec: '300'

I also changed my file to run test before analysis, that looks like this

trigger:
  branches:
    include:
      - develop
      - feature/

pool:
  vmImage: 'macOS-11'

stages:
  - stage: Setup
    jobs:
    - job: sonarcloud
      steps:
      - task: Xcode@5
        displayName: 'Build and run Unit Tests'
        inputs:
          actions: 'clean test'
          sdk: '$(sdk)'
          scheme: '$(scheme)'
          configuration: '$(configuration)'
          xcWorkspacePath: 'MyWorkspace.xcWorkspace'
          xcodeVersion: 'specifyPath'
          xcodeDeveloperDir: '/Applications/Xcode_13.2.1.app/Contents/Developer'
          exportPath: '$(Agent.buildDirectory)/output/$(sdk)/$(configuration)'
          destinationPlatformOption: iOS
          destinationSimulators: 'iPhone 11 Pro'
          useXcpretty: true
          publishJUnitResults: true
          packageApp: false
      - task: SonarCloudPrepare@1
        displayName: 'Prepare analysis on SonarCloud'
        inputs:
          SonarCloud: sonarCloudServiceConnection
          organization: myOrganization
          scannerMode: CLI
            
      - task: SonarCloudAnalyze@1
        displayName: 'Run Code Analysis'
          
      - task: SonarCloudPublish@1
        inputs:
          pollingTimeoutSec: '300'

I searched the internet and this community for an answer but I cannot find how to implement the test coverage.

The best source I have found is this one

However when I try to follow and run those scripts in the pipeline yaml it does not work.

Can someone explain me what I am missing. What are the steps I should include in the pipeline yaml, and what properties am I missing in the properties file.

Hey there.

What doesn’t work? Sharing an error message you received, where you ran into an issue… is critical for anybody to be able to point you to where to go next.

The error I get when running the pipeline is that the *.xcresult/ cannot be found.

For example

Coverage FILE NOT FOUND AT PATH: /Users/runner/work/1/output/*.xcresult/