Coverage always at 0% on sonarqube even i added test unit

Viewed 1385

I created a test unit for a class and it passed well on my local, on sonarqube it is shown as 0% for Coverage, I found post advice to add coverlet.msbuild I added but still no news:

   <PackageReference Include="xunit" Version="2.4.1" />
   <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
   <DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
   <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
   <PackageReference Include="coverlet.msbuild" Version="3.0.3">
     <PrivateAssets>all</PrivateAssets>
     <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 
   </PackageReference>
 </ItemGroup>

Any idea?

2 Answers

Try adding the following to your .csproj

<PropertyGroup>
  <DebugType>Full</DebugType>
</PropertyGroup>

<PackageReference Include="Microsoft.CodeCoverage" Version="16.9.4" />

Can you try coverlet.collector instead of coverlet.msbuild? I have personally used coverlet collector several times successfully.

<PackageReference Include="coverlet.collector" Version="1.3.0">
     <PrivateAssets>all</PrivateAssets>
     <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

According to this GitHub issue.

Collectors are pretty new(last arrived) and are the best way to do coverage because are strictly integrated with vstest platform(dotnet test) and due to that is the default choice for every .NET core xunit project by Microsoft. So if you create xunit project Microsoft xunit template inject by design our coverage engine as first class coverage tool running with dotnet test --collect:"XPlat Code Coverage"

It may be possible that you are running into this known issue.

Related