4

I am using dotnet dotcover test command in my gitlab-ci.yml to get the code coverage. I have included dotcover dotnetclitool version 2020.3.3 in my unit tests solution for this command to execute during the pipeline test stage. But i am not able to successfully exclude certain classes(under a specific namespace/folder) from the code coverage results. My solution structure is as follows:

  1. source folder
    • AClient.Repository.csproj
      • Extensions folder

        AClientExt.cs

      • Models folder

        ModelA.cs

        ModelB.cs

      • Repository folder

        RepoA.cs

        RepoB.cs

  2. tests folder
    • AClient.Repository.UnitTests.csproj
      • RepositoryTests

        RepoATests.cs

Now the code coverage includes both the solutions and I want to exclude the following namespaces:

AClient.Repository.Extensions.*
AClient.Repository.Models.*
AClient.Repository.Tests.*

I am running this command and it is not able to exclude the filters correctly so could someone please help me figure out correct usage of dcFilters: code coverage

Pooja Arya
  • 121
  • 1
  • 11

1 Answers1

5

I finally resolved it like this:

run-testCoverage:
  stage: dotnet-test
  image: mcr.microsoft.com/dotnet/core/sdk:3.1
  before_script:
    - cd tests/AClient.Repository.UnitTests
  script:
    - dotnet restore -v d
    - dotnet dotcover test --dcReportType=HTML --dcOutput=../../coverage/AppCoverageReport.html --dcFilters="+:AClient.Repository;-:type=AClient.Repository.Extensions.*;-:type=AClient.Repository.Models.*;-:type=AClient.Repository.UnitTests"

This is the answer that helped me: https://stackoverflow.com/a/6208644/11731377

Pooja Arya
  • 121
  • 1
  • 11