vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Code Coverage should not be checking the unit test projects themselves for coverage.

Open StingyJack opened this issue 6 years ago • 6 comments

Running the code coverage option from the test explorer will always display the coverage statistics for unit test assemblies, and this skews the overall results.

I'm aware that this can be excluded by using a runsettings/testsettings file, but that has become tedious after a hundred or so projects, especially since VS cant associate and remember the test settings file with the solution. The way it requires file naming is also easy to mess up.

There is a request open to permit the [ExcludeFromCodeCoverage] attribute to an assembly, but that is targeted to net core and not net framework.

Can unit test projects just be removed from the coverage stats by default, and still let those who want this opt in?

StingyJack avatar Apr 18 '18 18:04 StingyJack

Agreed with @StingyJack , To get proper coverage for product code only, Currently we have to pass runsettings. I run into same experience when try to get code coverage for vstest repo.

smadala avatar Apr 19 '18 07:04 smadala

Any exclude should be more than *.Test*.dll. It should at least be .*Test*.

Tests can live in .exe projects (as will be the case for xUnit 3.0), and they may be plural (foo.tests)

clairernovotny avatar Aug 02 '18 16:08 clairernovotny

This issue is open by 2018. I'm using collect:"Code coverage" (the new native ms dotnet coverage tool) and I create cobertura or . coverage results as well, but is painful using . runsettings configuration file for exclude tests and 3rd party libraries.

gioce90 avatar Feb 19 '22 18:02 gioce90

.runsettings workaround is not ideal because its default is to include all binaries including nuget dependencies, which means we have to specify both <Include> to include our namespaces and <Exclude> to exclude our tests. Worse, our dependencies share the same namespace prefix, so our regex list grows.

We tried specifying assembly level ExcludeFromCodeCoverage, but that didn't work. It doesn't look like it's respected by VS/dotnet test. This would have been an ideal solution since we can just decorate it on any test csproj.

devlie avatar Mar 25 '22 18:03 devlie

Is there any update on this one? I am trying to migrate from coverlet and using runsettings file doesn't feel good. It would be awesome to have some clever defaults. At least stop trying to cover all nuget dependencies

IvanAlekseev avatar May 23 '22 16:05 IvanAlekseev

Is there any update on this one? I am trying to migrate from coverlet and using runsettings file doesn't feel good. It would be awesome to have some clever defaults. At least stop trying to cover all nuget dependencies

@IvanAlekseev , please upvote microsoft/vstest#3669 and https://github.com/microsoft/vstest/issues/1050 so we can get some traction :)

devlie avatar May 23 '22 16:05 devlie