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:
Extensions folder
AClientExt.cs
Models folder
ModelA.cs
ModelB.cs
Repository folder
RepoA.cs
RepoB.cs
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:

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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With