-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Coverage should not be checking the unit test projects themselves for coverage. #20
Comments
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. |
Any exclude should be more than Tests can live in |
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. |
We tried specifying assembly level |
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 microsoft/vstest#1050 so we can get some traction :) |
It's available today going to close microsoft/vstest#3669 (comment) |
@MarcoRossignoli this should IMO be reopened as it doesn't fix the original issue - to automatically exclude test projects from the coverage - that is not implemented. We still need to manually add the |
Unfortunately, Microsoft.CodeCoverage package covers by default all assemblies with pdb existing. You can exclude using
|
Yeah I know this is possible, but think it should be excluded by default, as it doesn't really make sense in almost all of the possible cases I believe. The attribute is not available to be applied assembly-wide in older frameworks, so that's not a solution, and applying it class-by-class is tedious and error-prone... Runsettings are a way, but once again, I believe almost everybody using this doesn't want to have coverage counted for the test projects, so it's just an annoying repetitive stuff to add for every test run everywhere... It should be configurable, but rather as an opt-in, than opt-out IMHO... |
The issue is that many teams are collecting coverage also for test projects. Changing default behavior could break many solutions. |
@jakubch1 - are you being serious or sarcastic? |
You can check how often people are using option to collect for test projects here (this is for coverlet): https://github.com/search?p=4&q=IncludeTestAssembly&type=Code Microsoft.CodeCoverage is able to collect code coverage for both .NET and C++. In C++ world you often link statically to be tested code into test project so it is required in this case to enable coverage for test projects. For easier usage we could add
|
Yeah I thought that it would probably be a breaking change. But for me it was rather a surprise - I would guess the test assemblies get excluded by default. Only when I was solving an issue with report generation I found that it includes the test assemblies as well. And I guess most people think this way too - they run
I also wanted to suggest something similar, so I totally agree :) |
I think that trying to determine how well the code that is executed in production is covered by unit tests is valuable. I think that trying to calculate how well those unit tests are covered by an additional layer of unit tests is a waste of time. Anyone using coverage calculation in the latter example is probably doing so by mistake or has been misinformed. |
I think that this can be a good option, anyway I find also good reason sometime to have coverage of the test module, you can catch errors(mistakes in test filtering) that are not possible to catch simply looking to the production code coverage %. We had similar discussion on coverlet side coverlet-coverage/coverlet#618 |
@StingyJack I don't think (hope 😄) anybody writes tests that would test other tests. That would make sense probably only if you have a huge custom test framework. From what I've seen in my results, the test projects covered themselves. Makes sense that by getting code coverage of the tests, you see if you have some parts of tests that don't get executed. But I'd call this maybe an advanced thing. And you definitely don't want to raise the overall percentage of covered code by the coverage of the tests themselves. Personally I'd like to have two values - one for production code coverage, one for the test code coverage, should I ever need to have the value for tests. But this is of course another story. I can see that it would be a breaking change to change this behavior, wonder for how many people/projects, but still a breaking change so probably the best that can be done is to provide a simple way to control this behavior, as suggested before. |
We are considering adding new flag to easily exclude test projects so reopening this issue. |
this would be an awesome improvement! |
We have added new flag. In upcoming 17.8 release of our
Name of the flag is consistent with coverlet. |
Hi @jakubch1 , |
You can exclude these using runsettings file. https://learn.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2022#include-or-exclude-assemblies-and-members |
Sadly I think that .runsettings file is pure evil :D to manually add and remove lines from that file.... I think that a better out-of-the-box solution can be designed (IMHO) |
We are planning to add feature to make those exclusions simpler. We are thinking about specifying repo root dir: |
Interesting. However, why doesn't the code coverage focus on what we are testing as default behavior? In my company usually we do:
or
With I think Coverlet is already doing something like that:
they talk about it here coverlet-coverage/coverlet#1164 and also here If there are concerns about breaking changes, perhaps a flag called, for example, |
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?
The text was updated successfully, but these errors were encountered: