coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.99k stars 385 forks source link

Coverlet doesnot excludes cshtml files from coverage #986

Closed tavisca-vkapoor closed 4 years ago

tavisca-vkapoor commented 4 years ago

Coverlet.MsBuild:- 2.6.3 Framework Used:- .Net Core 2.1 Platform : Linux

Tried below commands

  1. dotnet2.1 test csprojfilename /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "trx;LogFileName=TestResults.trx" /p:ExcludeByFile="**/demo.services.host/Views/*/\.cshtml\"

  2. dotnet2.1 test csprojfilename /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger "trx;LogFileName=TestResults.trx" /p:Exclude=\"[xunit.*]*,[demo.services.host..cshtml]\\"

After trying both the commands the output is still same as shown below +--------------------------------------------------+--------+--------+--------+ | Module | Line | Branch | Method | +--------------------------------------------------+--------+--------+--------+ | demo.services.host.Views | 0% | 0% | 0% |

MarcoRossignoli commented 4 years ago

What version of coverlet you want to use?It's not clear you said Coverlet Console version:- 1.7.2 but used dotnet test command

The dotnet tool sample is https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/GlobalTool.md#code-coverage

Take a look at startup guide on coverlet flavours https://github.com/coverlet-coverage/coverlet#quick-start you can chose between msbuild integration(dotnet test) .NET tool coverlet and collectors --collect "XPlatCodeCoverage" if you're on .NET Framework you should use msbuild integration or the .NET tool, next version of coverlet will support collectors also for .NET Framework applications.

tavisca-vkapoor commented 4 years ago

Hey Marco,

Sorry for the wrong details Things i have used are below Coverlet.MsBuild:- 2.6.3 Framework Used:- .Net Core 2.1 Platform : Linux

I have also updated the details in original issue. remaining commands are correct and will remain same.

In the dotnet command, all the files are getting excluded except the cshtml files.

MarcoRossignoli commented 4 years ago

In the dotnet command, all the files are getting excluded except the cshtml files.

Coverlet instruments only dll assemblies...we cannot instrument any other file, what do you mean for "skip cshtml files"?

tavisca-vkapoor commented 4 years ago

yes, you are right coverlet instruments only dll assemblies. And yes dll is getting generated for views. But when we run the code coverage command , module containing the front end files ( .cshtml ) is shown in the report with 0% coverage. Assembly name:- Demo.Services.Host Folder containing the frontend files:- Demo.Services.Host.Views

After running the command the output displayed:- +--------------------------------------------------+--------+--------+--------+ | Module | Line | Branch | Method | +--------------------------------------------------+--------+--------+--------+ | demo.services.host.Views | 0% | 0% | 0% |

how can we exclude the coverage shown for above module "demo.services.host.Views" containing frontend files.

MarcoRossignoli commented 4 years ago

I think you could use filtering like [demo.services.host.Views]*

tavisca-vkapoor commented 4 years ago

Hey Marco, tried the command and working successfully. Thanks for helping out.

MarcoRossignoli commented 4 years ago

Glad to hear!

LearCore commented 1 year ago

Hi I am having same issue i am not able to exclude Views- .cshtml from coverge My Folder sstructure in solution is .Web /Views- .cshtml files in the coverge result it is showing as AspNetCoreGeneraterDocumnet is 0 % . Please help which command should be used to exclude .cshtml pages

horusceridian commented 1 year ago

Hey Marco, tried the command and working successfully. Thanks for helping out.

Could you share the command line, please?