vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Cobertura Code Coverage Breaks In Migrating from v17.8 to v17.9

Open dean-dot-git opened this issue 1 year ago • 1 comments

Description

Please help! I am not an expert by any means. Need the community's help.

I updated my testing nuget package for the SDK from 17.8 to 17.9. Azure DevOps is now unable to generate and display a code coverage report.

Working proj file snippet: <ItemGroup> <PackageReference Include="coverlet.collector" Version="6.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageReference Include="Moq" Version="4.20.70" /> <PackageReference Include="MSTest.TestAdapter" Version="3.2.2" /> <PackageReference Include="MSTest.TestFramework" Version="3.2.2" /> </ItemGroup>

to

Broken proj file snippet: <ItemGroup> <PackageReference Include="coverlet.collector" Version="6.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> <PackageReference Include="Moq" Version="4.20.70" /> <PackageReference Include="MSTest.TestAdapter" Version="3.2.2" /> <PackageReference Include="MSTest.TestFramework" Version="3.2.2" /> <PackageReference Include="ReportGenerator" Version="5.2.2" /> </ItemGroup>

Here is a snippet from my pipeline yaml:

- task: DotNetCoreCLI@2 displayName: 'Run Unit Tests' condition: and(succeeded(), ne('${{ parameters.unitTestsProjectPath }}', '.')) inputs: command: 'test' projects: '${{ parameters.unitTestsProjectPath }}' arguments: '--no-build --logger trx --results-directory "$(Build.SourcesDirectory)/TestResults/" --collect "XPlat Code Coverage" --settings "$(runSettings.secureFilePath)"' publishTestResults: false env: Environment: $(environment) AzureTenantId: $(azureTenantId) DevOpsClientId: $(devOpsClientId) DevOpsClientSecret: $(devOpsClientSecret) - task: PublishTestResults@2 displayName: 'Publish Test Results' condition: and(succeededOrFailed(), or(ne('${{ parameters.unitTestsProjectPath }}', '.'), ne('${{ parameters.integrationTestsProjectPath }}', '.'))) inputs: testRunner: VSTest testResultsFiles: '**/*.trx' searchFolder: '$(Build.SourcesDirectory)\TestResults' - task: reportgenerator@5 displayName: 'Generate Code Coverage Report' condition: and(succeeded(), ne('${{ parameters.unitTestsProjectPath }}', '.')) inputs: reports: '$(Build.SourcesDirectory)\**\coverage.cobertura.xml' targetdir: '$(Build.SourcesDirectory)\CodeCoverageReport' reporttypes: 'HtmlInline_AzurePipelines;Cobertura' - task: PublishCodeCoverageResults@1 displayName: 'Publish Code Coverage Results' condition: and(succeeded(), ne('${{ parameters.unitTestsProjectPath }}', '.')) inputs: codeCoverageTool: Cobertura summaryFileLocation: '$(Build.SourcesDirectory)\CodeCoverageReport\Cobertura.xml' reportDirectory: '$(Build.SourcesDirectory)\CodeCoverageReport' env: DISABLE_COVERAGE_AUTOGENERATE: 'true'

Steps to reproduce

Just upgrade from 17.8 to 17.9 version of the SDK.

Expected behavior

Show the report generator coverlet created report.

Actual behavior

Gives the standard code coverage page in Azure Pipelines instead of the coverlet one.

Diagnostic logs

DevOps indicates no errors during the process. Found that the coverage_cobertura.xml file is exactly the same between the two versions (minus the time stamp). However the ".coverage" files look way different. Clearly something is broken for 17.9 with my setup. I am able to kind of view the coverage files via a text editor and I don't see any .cs files in the ".coverage" file.

What changed? What am I doing wrong?

dean-dot-git avatar Feb 26 '24 00:02 dean-dot-git

I can see that the report generator files are there. I can see and access them. It is a matter of it not displaying in DevOps correctly? It seems like it is getting most of the way there....

dean-dot-git avatar Feb 26 '24 05:02 dean-dot-git

You are mixing usage of 2 different tools. Cobertura reports are generated by coverlet. .coverage reports are generated by Microsoft.CodeCoverage. I suggest usage of one of those tools in azure pipelines only.

  1. --collect "XPlat Code Coverage" enables coverlet
  2. --collect "Code Coverage" enables Microsoft.CodeCoverage

jakubch1 avatar Mar 08 '24 12:03 jakubch1