dotnet test --collect:"XPlat Code Coverage" not consider Api project

1.9k views Asked by At

I am trying to generate Code coverage report in 2 ways.

  1. Using Fine Code Coverage. There i see all 3 projects of me covered & its % of coverage.
  2. Using Azure devops Pipeline where i use DotNetCoreCLI@2& PublishCodeCoverageResults@1 to build & generate the report. But the issue is API project is not considered in the report. both in trx & xml file.

So i tried MSBuild commands to repro the issue. To run the test cases & to build the xml file i am using below command.

dotnet test --collect:"XPlat Code Coverage"   

After that to publish the coverage using below command.

dotnet test /p:CollectCoverage=true

Issue:- In above command also , i don't see my Api Project is getting into report, where as i see the API layer unit test are running.

Below is my project structure( using clean code architecture/Onion architecture)

enter image description here

Why only API is getting excluded , where as all unit test are running for the same.

1

There are 1 answers

0
Mauricio Atanache On

Look into your unit test project file, if you see this package reference:

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

Replace it with this:

<PackageReference Include="coverlet.collector"/>