Dotnet project showing code coverage 0% - Azure DevOps

Hi Everyone
We have Dotnet 6.0 project in Azure repos for which we have integrated sonar cloud using the azure devops

  • ALM used Azure DevOps
  • CI system used Azure DevOps
  • Languages of the repository - Dotnet 6.0

Since last few runs , code coverage is always showing as 0% (it used to show us some value before)

Prepare analysis configuration – additional properties -sonar.exclusions=/obj/,/*.dll
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/
/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx

Dot net task - Test - Arguments-
-configuration Release /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --logger trx --collect “Code Coverage”

image

image

Hey there.

What do the logs say about the import of code coverage?

Hi Colin,

I have another dotnet project where code coverage is reflecting for which we have used the same sonar configuration and dotnet test task arguments. So, I have compared between logs between these projects and found the following difference

logs of Dotnet project for which code coverage is calculating

Sensor C# Tests Coverage Report Import [csharp]
WARN: Could not find any coverage report file matching the pattern ‘D:\a\1\s/**/coverage.opencover.xml’. Troubleshooting guide: [Coverage] Troubleshooting guide for .NET code coverage import
INFO: Parsing the Visual Studio coverage XML report D:\a_temp\6b5c2bc9-e001-49c7-8edc-c7ba05a61044\VssAdministrator_fv-az2457-7_2024-06-27.05_18_16.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: D:\a_temp\6b5c2bc9-e001-49c7-8edc-c7ba05a61044\VssAdministrator_fv-az2457-7_2024-06-27.05_18_16.coveragexml
INFO: Coverage Report Statistics: 111 files, 94 main files, 94 main files with coverage, 17 test files, 0 project excluded files, 0 other language files.
INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=661ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the Visual Studio Test Results file ‘D:\a_temp\VssAdministrator_fv-az2457-7_2024-06-27_05_18_21.trx’.
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=19ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=3ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 178 source files to be analyzed
WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with ‘git fetch --unshallow’.
INFO: SCM Publisher 0/178 source files have been analyzed (done) | time=13ms

logs of Dotnet project for which code coverage is 0% always

Sensor C# Tests Coverage Report Import [csharp]
2024-06-28T05:33:37.3027069Z WARN: Could not find any coverage report file matching the pattern ‘/home/vsts/work/1/s/**/coverage.opencover.xml’. Troubleshooting guide: [Coverage] Troubleshooting guide for .NET code coverage import
2024-06-28T05:33:37.3036711Z INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=31ms
2024-06-28T05:33:37.3044238Z INFO: Sensor C# Unit Test Results Import [csharp]
2024-06-28T05:33:37.3096091Z INFO: Parsing the Visual Studio Test Results file ‘/home/vsts/work/_temp/_fv-az407-33_2024-06-28_05_32_00.trx’.
2024-06-28T05:33:37.4426486Z INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=138ms
2024-06-28T05:33:37.4439788Z INFO: Sensor Zero Coverage Sensor
2024-06-28T05:33:37.5238431Z INFO: Sensor Zero Coverage Sensor (done) | time=80ms
2024-06-28T05:33:37.5334399Z INFO: SCM Publisher SCM provider for this project is: git
2024-06-28T05:33:37.5359458Z INFO: SCM Publisher 1056 source files to be analyzed
2024-06-28T05:33:37.5391640Z WARN: Shallow clone detected, no blame information will be provided. You can convert to non-shallow with ‘git fetch --unshallow’.
2024-06-28T05:33:37.5399567Z INFO: SCM Publisher 0/1056 source files have been analyzed (done) | time=2ms

For these two projects, able to generate .trx file and …coverage file

Could you please help me with these details

Thank you

Is there any difference in the configuration of your SonarCloudPrepare tasks, specifically where you may explicitly be pointing to a coverage report in one but not the other? You should make sure you check the Advanced > Additional properties section of this task.

No, for both the projects we are using the same additional properties as following

sonar.exclusions=/obj/,/*.dll
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/
/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx

Then I think you’ll have to check if the file (coverage.opencover.xml) really exists for your second project. Probably, there’s some difference in the configuration of how the code coverage repot is generated.

Long story short – make sure for the second project that coverage.opencover.xml really exists where you expect it to.