1
votes

In azure devops build pipeline, I am having the below stages.

  • Prepare analysis on sonar cloud
  • dotnet restore
  • dotnet build
  • dotnet test
  • dontnet publish
  • copy test files .. this for copying (*.trx *.xml) to respective directory.
  • Run code analysis
  • Publish quality gate result.

here my pipeline runs successfully with the tests but its not giving code coverage. code coverage showing 0.00%

*.trx file is copying on the required path & I have also tried with the default path of trx file but its giving below message in logs.

ERROR MESSAGE

Post-processing started.
00:23:49.775  Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders.
00:23:49.995  Did not find any binary coverage files in the expected location.
00:23:49.995  Falling back on locating coverage files in the agent temp directory.
00:23:49.995  Searching for coverage files in D:\a\_temp
00:23:49.995  No coverage files found in the agent temp directory.
WARNING: The following projects do not have a valid ProjectGuid and were 
not built using a valid solution (.sln) thus will be skipped from 
analysis...
D:\a\1\s\Rost.API.Tests\Rost.API.Tests.csproj

I expect the code coverage in the pipeline, currently code coverage showing 0.00%.

1

1 Answers

2
votes

May i confirm several questions with you?

  1. Did you add --collect "Code coverage" option to the command line arguments? enter image description here

Code coverage can be collected by adding --collect "Code coverage" option to the command line arguments. This is currently only available on the Windows platform.

  1. If run the test command on local, did the code coverage show correctly?

BTW, SonarQube requires a valid Project GUID but Core projects dont actually use this.It is recommended to add the ProjectGUID in the test project file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!-- SonarQube requires a valid Project GUID but Core projects dont actually use this -->
    <ProjectGuid>{9C99E491-F56E-4515-9F0B-D72A5207DB13}</ProjectGuid>
  </PropertyGroup>
</Project>