No Code coverage showing for a MAUI project

Template for a good new topic, formatted with Markdown:

  • We are using Azure Dev Ops for our CI builds and Source Control Repo
  • Our CI build is pretty much a duplicate of our old but working Xamarin Forms build that we ported to a new repo
  • Project is C# and XAML

When the CI build runs the unit test we get a coverage report that looks like this (in the Azdo Logs). I am aware of the appalling low coverage numbers but I’ve had a nightmare porting over Unit Tests from the Xamarin Forms repo

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: D:\a\1\TestResults\pbf.results.trx

Passed!  - Failed:     0, Passed:   129, Skipped:     0, Total:   129, Duration: 1 s - ProjectBreatheApp.Maui.UnitTests.dll (net9.0)
  [coverlet] 
  Calculating coverage result...
   Generating report 'D:\a\1\TestResults\pbf.opencover.net9.0.xml'

+------------------------------------+-------+--------+--------+
| Module                             | Line  | Branch | Method |
+------------------------------------+-------+--------+--------+
| MagicBullet.Common                 | 100%  | 100%   | 100%   |
+------------------------------------+-------+--------+--------+
| MagicBullet.Common.Fake            | 100%  | 100%   | 100%   |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.AppleHealth.Fake | 0%    | 100%   | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Common           | 0%    | 0%     | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Data             | 100%  | 100%   | 100%   |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Devices.Mir.Fake | 0%    | 0%     | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp                  | 7.86% | 3.87%  | 9.42%  |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Maui             | 8.71% | 7.73%  | 7.84%  |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Maui.Fake        | 0%    | 100%   | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Mir.Common       | 0%    | 0%     | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Notifications    | 0%    | 100%   | 0%     |
+------------------------------------+-------+--------+--------+
| ProjectBreatheApp.Values           | 0%    | 0%     | 0%     |
+------------------------------------+-------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 8.08%  | 6.86%  | 7.55%  |
+---------+--------+--------+--------+
| Average | 26.38% | 50.96% | 26.43% |
+---------+--------+--------+--------+

What should I be looking for in the Sonarcloud analyze step that would tell me what the issue is that is preventing me getting any code coverage value in SonarCloud?

This is some of the mor pertinent information in the Azdo CI Logs

2025-02-19T17:44:36.5932550Z sonar.scanner.scanAll=false
2025-02-19T17:44:36.5932725Z sonar.visualstudio.enable=false
2025-02-19T17:44:36.5932813Z 
2025-02-19T17:44:36.5933726Z sonar.modules=0310A8F4-CC2F-483E-954C-31EF7E225DC8,B2DEFBE6-2705-4179-89DA-FB7CD48120F2,E0FD2A1D-D087-4501-BC1C-021C6D0F8D32,62FE6DE4-DBC2-4FDE-8AA0-53A519FA4FD8,6764B850-2A8C-4B86-B7B9-07532D2C83AF,90F05D94-A572-4876-BA11-CFD3A64EB4E0,9BC71C4C-A34C-4FA4-B623-86A1F32F1138,1D6B6772-89B1-4156-9501-AF1F46F8F48C,068D41A8-935E-4254-8347-DB1059927F3B,C868A2EC-BA18-4452-BD49-5CB60D5384EC,C7F9A59E-2C55-436D-B688-166EBF37AB32,C5F3AD88-E825-4334-9A09-0FED6B2E4A15,9D4BD988-8B5E-4276-B623-95CB33652B80,7A6F2F39-FE45-4091-AD77-7CDB7A7B7EFD,0BA01DC9-A30B-435F-A166-242FFF8F5061,FE3CE511-9AA9-4E06-8C55-512ADEF721F6,F3EB2D87-F74A-4B87-B8B9-327B6BCFFDFE,F4F816F5-063A-4B73-B12C-764E91895D46,110172D1-1E9D-4ACD-816D-426D4263DEB2,CC63D760-71B3-4615-B34D-CA5AF02F78FC,7580F0E5-D1D8-4A30-9E20-A5EA4A13871B,07A8D30F-8207-457D-9757-C01A3038D682,070C1203-3738-4537-A596-4359FADED9BF,8CE954DE-07E1-4B67-A451-FC082457682B,BE987523-0EE8-4599-B4A7-A033439E920B
 2025-02-19T17:44:36.5934536Z 
2025-02-19T17:44:36.5934585Z 
2025-02-19T17:44:36.5934793Z ------------------------------------------------------------------------
2025-02-19T17:44:36.5935049Z 17:44:36.547  Writing processing summary to D:\a\1\.sonarqube\out\ProjectInfo.log
2025-02-19T17:44:36.5935284Z Calling the TFS Processor executable...
2025-02-19T17:44:36.5974030Z Executing file D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\3.1.1\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.TFSProcessor.exe
2025-02-19T17:44:36.5975587Z   Args: ConvertCoverage D:\a\1\.sonarqube\conf\SonarQubeAnalysisConfig.xml D:\a\1\.sonarqube\out\sonar-Project.properties 
2025-02-19T17:44:36.5976213Z   Working directory: D:\a\1
2025-02-19T17:44:36.5978138Z   Timeout (ms):-1
2025-02-19T17:44:36.5980247Z   Process id: 6728
2025-02-19T17:44:36.7322283Z Fetching code coverage report information from TFS...
2025-02-19T17:44:36.7338005Z Attempting to locate a test results (.trx) file...
2025-02-19T17:44:38.6203513Z Looking for TRX files in: D:\a\1\TestResults
2025-02-19T17:44:38.6208905Z The following test results files were found: D:\a\1\TestResults\pbf.results.trx
2025-02-19T17:44:39.4708480Z No code coverage attachments were found from the trx files.
2025-02-19T17:44:39.4709500Z Not using the fallback mechanism to detect binary coverage files.
2025-02-19T17:44:39.4709990Z Coverage report conversion completed successfully.
2025-02-19T17:44:39.4867996Z Process returned exit code 0
025-02-19T17:45:24.5424137Z 17:45:24.272 INFO: Sensor C# File Caching Sensor [csharpenterprise] (done) | time=237ms
2025-02-19T17:45:24.5424409Z 17:45:24.272 INFO: Sensor C# Tests Coverage Report Import [csharpenterprise]
2025-02-19T17:45:24.5424693Z 17:45:24.273 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir 'D:\a\1\.' and file separator '\'.
2025-02-19T17:45:24.5425034Z 17:45:24.273 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\1\TestResults' from the given pattern 'D:\a\1\TestResults\*.opencover.xml'.
2025-02-19T17:45:24.5425342Z 17:45:24.274 DEBUG: Gathering files for wildcardPattern '*.opencover.xml'.
2025-02-19T17:45:24.5425586Z 17:45:24.274 DEBUG: Pattern matcher returns '0' files.
2025-02-19T17:45:24.5425904Z 17:45:24.274 WARN: Could not find any coverage report file matching the pattern 'D:\a\1\TestResults\*.opencover.xml'. Troubleshooting guide: https://community.sonarsource.com/t/37151
2025-02-19T17:45:24.5426236Z 17:45:24.275 DEBUG: Analyzing coverage after aggregate found '0' coverage files.
2025-02-19T17:45:24.5426478Z 17:45:24.275 DEBUG: The total number of file count statistics is '0'.
2025-02-19T17:45:24.5426729Z 17:45:24.275 INFO: Sensor C# Tests Coverage Report Import [csharpenterprise] (done) | time=3ms
2025-02-19T17:45:24.5426984Z 17:45:24.276 INFO: Sensor C# Unit Test Results Import [csharpenterprise]
2025-02-19T17:45:24.5427293Z 17:45:24.276 DEBUG: Pattern matcher extracted prefix/absolute path 'D:\a\1\TestResults\pbf.results.trx' from the given pattern 'D:\a\1\TestResults\pbf.results.trx'.
2025-02-19T17:45:24.5427631Z 17:45:24.276 DEBUG: Pattern matcher returns a single file: 'D:\a\1\TestResults\pbf.results.trx'.
2025-02-19T17:45:24.5427926Z 17:45:24.277 INFO: Parsing the Visual Studio Test Results file 'D:\a\1\TestResults\pbf.results.trx'.

Hey there.

If you’ve got an opencover report at:

You should point the analysis parameter sonar.cs.opencover.reportsPath to it!

The filename (pbf.opencover.net9.0.xml) isn’t matching the default value of sonar.cs.opencover.reportsPath (*.opencover.xml)

You probably want to set sonar.cs.opencover.reportsPath to something like **/*.opencover.net9.0.xml.

Sorry it’s taken so long to reply, so much to do and a very small team.

I made your suggested change to sonar.cs.opencover.reportsPath a while back but I still saw 0% code coverage.

I looked again today and noticed that the Unit test run step is creating a file named “pbf.opencover.net9.0.net9.0.xml”!

Yes “net9.0” twice despite the setting /p:CoverletOutput=$(Common.TestResultsDirectory)\pbf.opencover.net9.0.xml

I have no idea why it does that but I have since set path to the silly but correct name and I now have coverage in sonarcloud

Thanks