Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude AspNetCoreGeneratedDocument Class from coverage report in coverlet

I have this class AspNetCoreGeneratedDocument.Views_Users__AddOrUpdateUser appearring in the code coverage result for each view in the Views folder,

Exemple: AspNetCoreGeneratedDocument.Views_Users__AddOrUpdateUser AspNetCoreGeneratedDocument.Views_Users__GetUser etc...

Assembly: Solution.Web Class: AspNetCoreGeneratedDocument

I want to exclude this folder using the .runsettings file:

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <DataCollectionRunSettings>
        <DataCollectors>
            <DataCollector friendlyName="XPlat code coverage">
                <Configuration>
                    <!-- Globbing filter -->
                    <ExcludeByFile>**/Solution.Web/Views/*.cshtml</ExcludeByFile>
                    <IncludeTestAssembly>false</IncludeTestAssembly>
                    <DeterministicReport>false</DeterministicReport>
                </Configuration>
            </DataCollector>
        </DataCollectors>
    </DataCollectionRunSettings>
</RunSettings>

this is the result i want: this image is from dotCover it allows creating a filter easily enter image description here

like image 298
KA-Yasso Avatar asked Aug 11 '26 08:08

KA-Yasso


1 Answers

A year an a half later and the correct answer is ...

<ExcludeByFile>**/*.cshtml</ExcludeByFile>

So @KA-Yasso code partially works.
It does not does not exclude all of the .cshtml files from the Views folder.

It excludes only the .cshtml files at the root level of the Views folder like _ViewStart.cshtml.
It does not exclude the files that he actually wants to exclude like Views/Users/AddOrUpdateUser.cshtml.

The answer by @red is not meant for coverlet, it won't work, the .runsettings.xml file structure is different.

Exclude all .cshtml files

<ExcludeByFile>**/*.cshtml</ExcludeByFile>

Exclude all .cshtml files from the MainApp.MVC/Views folder

<ExcludeByFile>**/MainApp.MVC/Views/*.cshtml,**/MainApp.MVC/Views/**/*.cshtml</ExcludeByFile>

Exclude all .cshtml fles from an Area Views folder

<ExcludeByFile>**/MainApp.MVC/Areas/Common/Views/*.cshtml,**/MainApp.MVC/Common/Views/**/*.cshtml</ExcludeByFile>

Documentation:
  • Coverlet integration with VSTest (a.k.a. Visual Studio Test Platform)
  • Coverlet integration with MSBuild
Considerations:
  • Only the first xml element <ExcludeByFile> is applied.
  • You can add more but they are ignored.
  • Instead, you need to concatenate different patterns with a ',' inside a single <ExcludeByFile>.
like image 82
terodaktil Avatar answered Aug 13 '26 22:08

terodaktil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!