Branch Coverage on C# projects

I am trying to get branch level code coverage reported for my C# projects. Currently I have line/statement level code coverage working by using vstest and my azure devops pipeline is uploading the *.coverage file

  • sonarqube 10.6
  • self hosted

here is the output of working “line coverage” test output

Results File: C:\agent\_work\_temp\TestResults\xxbuilder_WIN22BUILD21_2024-11-07_15_50_03.trx
Attachments:
  C:\agent\_work\_temp\TestResults\44abe929-6eb4-4b7d-9c4b-e832207a05b0\xxbuilder_WIN22BUILD21_2024-11-07.15_50_13.coverage
Test Run Successful.
Total tests: 350
     Passed: 350
 Total time: 1.1047 Minutes
Vstest.console.exe exited with code 0.
**************** Completed test execution *********************
Test results files: C:\agent\_work\_temp\TestResults\xxbuilder_WIN22BUILD21_2024-11-07_15_50_03.trx

here is the currently working with line/statement coverage files

Searching for coverage files in C:\agent\_work\_temp
All matching files: count=2

C:\agent\_work\_temp\TestResults\f0a3aeb9-b564-407a-b365-8996a637c77e\xxbuilder_WIN22BUILD22_2024-11-08.09_14_28.coverage
C:\agent\_work\_temp\TestResults\xxbuilder_WIN22BUILD22_2024-11-08_09_13_47\In\WIN22BUILD22\rbbuilder_WIN22BUILD22_2024-11-08.09_14_28.coverage

Unique coverage files: count=1
C:\agent\_work\_temp\TestResults\f0a3aeb9-b564-407a-b365-8996a637c77e\xxbuilder_WIN22BUILD22_2024-11-08.09_14_28.coverage

Converting coverage file 'C:\agent\_work\_temp\TestResults\f0a3aeb9-b564-407a-b365-8996a637c77e\xxbuilder_WIN22BUILD22_2024-11-08.09_14_28.coverage' to 'C:\agent\_work\_temp\TestResults\f0a3aeb9-b564-407a-b365-8996a637c77e\xxbuilder_WIN22BUILD22_2024-11-08.09_14_28.coveragexml'.

Coverage report conversion completed successfully.

now the cobertura style that is not uploading to sonarqube

here’s the setup to output cobertura format

Results File: C:\agent\_work\_temp\TestResults\xxbuilder_WIN22BUILD21_2024-11-08_10_59_37.trx
Attachments:
  C:\agent\_work\_temp\TestResults\55b4c915-6ea4-4980-8119-56b2d00a474e\xxbuilder_WIN22BUILD21_2024-11-08.10_59_46.cobertura.xml
Test Run Successful.
Total tests: 350
     Passed: 350
 Total time: 1.1120 Minutes
Vstest.console.exe exited with code 0.
**************** Completed test execution *********************
Test results files: C:\agent\_work\_temp\TestResults\xxbuilder_WIN22BUILD21_2024-11-08_10_59_37.trx

no coverage found using cobertura

Calling the TFS Processor executable...
Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
Did not find any binary coverage files in the expected location.
Falling back on locating coverage files in the agent temp directory.
Searching for coverage files in C:\agent\_work\_temp
No coverage files found in the agent temp directory.
Coverage report conversion completed successfully.

Hey there.

SonarQube does not supported the upload of Cobertura-style reports for .NET code coverage. You can find the supported formats here

Off the top of my head, I know that at least coverlet supports branch coverage.