Code Coverage and Number of tests shown in Azure Devops and SonarQube are different

In my project we are trying to run the XUnit test cases and code coverage using the VS Test task as shown below.

- task: VSTest@2
  displayName: Test
    testAssemblyVer2: |
    resultsFolder: '$(Agent.BuildDirectory)\TestResults'
    runInParallel: true
    runTestsInIsolation: true
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    rerunFailedTests: true

And the generated .trx file will be used for Run Code Analysis task which is shown below

- task: sonarsource.sonarqube.6D01813A-9589-4B15-8491-8164AEB38055.SonarQubeAnalyze@5
  displayName: 'Run Code Analysis'

When we observe the result in the Code Coverage and number of test cases in Sonarqube has higher values that Azure devops values. I have not explicitly mentioned any inclusions/exclusions.


Welcome to the community!

I have no idea why the number of test cases would be different. We go 100% by the reports you pass in on that. For coverage, this dusty-but-still-relevant blog post should help.