Azure Devops / Sonarcloud - New code showing zero coverage although project coverage populated


We are building c# products with NUnit tests. On the main sonarcloud screen for our project, we have code coverage reported, so I assume we have unit test execution configured and running correctly:


However, if I create a new PR, it shows 0% coverage - I created a branch which has a class with 2 new methods, one tested and one not, in order to prove out a 50% new code coverage rate:


The test which runs against one of the methods in the test class is definitely executing as I have an extra test in the count (was previously 94, is now 95):

I have noticed this in the SonarCloudAnalyze output:

*INFO: Parsing the OpenCover report D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx*

**WARN: Could not import coverage report 'D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx' because 'Missing root element <CoverageSession> in D:\a\_temp\VssAdministrator_fv-az454-112_2022-03-23_15_40_27.trx at line 2'. Troubleshooting guide:**

*INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml*

*INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml*

*INFO: Coverage Report Statistics: 35 files, 30 main files, 30 main files with coverage, 5 test files, 0 project excluded files, 0 other language files.*

This is the only thing I can think of which could be causing the issue - but if it’s causing it for new code, how would we be showing any coverage at all? Any help would be greatly appreciated thank you

Hey there.

  • How have you configured the passing of analysis reports (how is sonar.cs.opencover.reportsPaths and any other relevant analysis parameters configured)?
  • Have you checked the coverage report (independently of SonarQube) to see if it shows these lines as covered?

Hi Colin,

In our SonarCloudPrepare task I have:

extraProperties: |
      # Additional properties that will be passed to the scanner, 
      # Put one key=value per line, example:
      # sonar.exclusions=**/*.bin

In our test execution:

task: DotNetCoreCLI@2
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --collect "Code Coverage"'

Then the publish task

- task: PublishTestResults@2
    testResultsFormat: 'VSTest'
    testResultsFiles: '$(Agent.TempDirectory)/**.*trx'

I am frustratingly unable to open the .trx file locally as the version of visual studio we’re using doesn’t have the .dll files to process it.

Hey @CraigF

.trx files are Test Result files, so passing these to sonar.cs.opencover.reportsPath is doing… nothing. It looks like the pipeline is automatically picking up the .coveragexml file:

INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\d25f7b86-f8f4-4aba-9f75-776481c8a656\VssAdministrator_fv-az454-112_2022-03-23.15_40_24.coveragexml

This file you should be able to open pretty easily as it’s just an XML file.

Hi @Colin

I’ve found and fixed the issue.

I needed to change




in the extraProperties section of the SonarCloudPrepare task

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.