Test Coverage is not shown for all targets in the project

  • SonarQube: * Version 7.9.1 (build 27448)

  • I want to get tests coverage for all targets created in the project

  • iOS (Swift) application is structured on a modular way, where through the main target all other targets (frameworks) are executed when running and testing

  • This is how my sonar-project.properties file looks like:

      sonar.projectKey=projectKey
      sonar.projectName=projectName-iOS
      sonar.projectVersion=1.0.0
      nca.project.id=id-number
      sonar.infostore.groupId=groupId.sonar
      sonar.infostore.artifactId=artifactId-iOS
      artifactId=artifactIs-iOS
      sonar.language=swift
    
      # Project description
      sonar.projectDescription=Project description
       
      # Path to source directories 
      sonar.sources=.
    
      sonar.c.file.suffixes=-
      sonar.cpp.file.suffixes=-
      sonar.objc.file.suffixes=-
       
      sonar.swift.project=Project.xcodeproj
      sonar.swift.workspace=Project.xcworkspace
      sonar.swift.simulator=platform=iOS Simulator,name=iPhone 12,OS=14.5
    
      # Scheme to build your application
      sonar.swift.appScheme=Project
    
      # Path to test directories (comment if no test)
      sonar.tests=ProjectTests,ProjectUITests,ProjectCoreTests,ProjectAccountsTests,ProjectCardsTests,ProjectPaymentsTests,ProjectDashboardTests,ProjectWebTests,ProjectAuthenticationTests,ProjectAppSettingsTests
      sonar.test.inclusions=*Tests/*.swift
    
      # Encoding of the source code
      sonar.sourceEncoding=UTF-8
    
      sonar.junit.reportsPath=sonar-reports/
    
      # Exclude directories from tests
      sonar.exclusions=build/derivedData/SourcePackages/checkouts/**,_assets/*,Certificates/*,fastlane/**,Pinpoint/*,Pods/**/*,Scripts/*,WIP/*
      sonar.test.exclusions=**/*.xml,sonar-reports/*
    

Only for main project scheme “Project” unit test coverage is shown and for others (like “ProjectCore”, “ProjectAccounts” etc.) is always 0% of coverage even though it is not like that in the project.
I tried different kind fo combination for inclusion of that code and nothing helped.
Interesting thing is that “Bugs”, “Vulnerabilities”, “Code Smells”, “Security Hotspots”, “Duplications” are showing correct results of percentages but “Coverage” is always 0% for all other targets in the project other that “Project” target.

Please advise in which direction should I go.

Thank you in advance!

Nikola

Hey there.

What Edition of SonarQube are you using?

Hi Colin. It is: Developer Edition Version 7.9.1 (build 27448)

Thanks.

I"m assuming your using the built-in Swift analyzer (made by SonarSource and bundled with the Developer Edition) rather than Idean/sonar-swift

Which, if true, means that these settings are having zero effect. Just a side note not really relevant here, but maybe it spruces up your project files. :slight_smile:

sonar.swift.project=Project.xcodeproj
sonar.swift.workspace=Project.xcworkspace
sonar.swift.simulator=platform=iOS Simulator,name=iPhone 12,OS=14.5

#Scheme to build your application
sonar.swift.appScheme=Project

To import coverage on Swift projects, you have two options as noted in the. documentation on Test Coverage & Execution

Language Property Remarks
Swift, Xcode 9.3+ You can use the xccov-to-sonarqube-generic.sh script from the sonar-scanning-examples/swift-coverage project convert output from Xcode 9.3’s xccov tool to the Generic Test Data format.
Swift, Xcode 7-9.2 sonar.swift.coverage.reportPath Path to the report generated by llvm-cov show . Path may be absolute or relative to project root.

You will need to make sure you have coverage reports being produced for all of your code and passed to the correct analysis parameter for coverage to be displayed.

There’s also a community guide available here:

Thank you Colin for the response. Basically you’re saying that I need to use Idean/sonar-swift so that I can get tests coverage from all of the targets. Right? - Since I tried out with additional settings from the documentation that you did provide here on top of the current setup and it doesn’t work on that way.

That is not what I said! I was just letting you know that unless you were using that community-supported plug-in, you have some useless settings in your sonar-project.properties file.

If you’ve gone about trying to set coverage reports using the parameters listed above, you’ll need to go into detail about what you’ve tried and what hasn’t worked (adding analysis logs, the different settings you’ve tried, commands run to generate coverage reports etc.)