Skip to content
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

Coverlet is not considering the excludefromCoverage attribute at method level #809

Closed
VenkateshSrini opened this issue Apr 12, 2020 · 18 comments
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage

Comments

@VenkateshSrini
Copy link

Hi,
I'm using the Coverlet to measure .NET core 3.1 Web API code coverage. I have used entity framework for creating by repository. There are some methods have anonymous object as return types and hence could not be unit tested. I want those methods to be alone excluded from coverage so I used [ExlcudeFromCodeCoverage] on those methods only. But Coverlet is not considering that at all and still generated the code coverage for the same. Please see the method EditTask in the TaskRepo class as an example in the attached code.
TaskApi.zip

@MarcoRossignoli MarcoRossignoli added the untriaged To be investigated label Apr 13, 2020
@MarcoRossignoli
Copy link
Collaborator

Thank's for repro, I'll take a look asap.

@MarcoRossignoli MarcoRossignoli added needs more info More details are needed and removed untriaged To be investigated labels Apr 17, 2020
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Apr 17, 2020

@VenkateshSrini can you tell me where is these methods? I searched [ExlcudeFromCodeCoverage] inside a solution but didn't found anything.

@MarcoRossignoli
Copy link
Collaborator

@VenkateshSrini any news?

@VenkateshSrini
Copy link
Author

In the repository folder, there is a file called TaskRepo.cs. In that, there is a method called EditTask that has [ExcludeFromCodeCovergae]

@MarcoRossignoli
Copy link
Collaborator

I cannot see the attribute what am I missing?
image

@VenkateshSrini
Copy link
Author

VenkateshSrini commented May 10, 2020

No. I just downloaded the attached code bit I'ma able to see the same. Let me upload it once again
TaskApi.zip. please see the code below
image

Please click on the link on this post to download it

@MarcoRossignoli
Copy link
Collaborator

Ok now I can repro, seems a bug, btw you cannot use /p:ExcludeByAttribute="CompilerGenerated" with new version because we fixed a bug and now you lose coverage with every async state machine generated #794 (comment)

Thanks for reporting this.

@MarcoRossignoli MarcoRossignoli added bug Something isn't working tenet-coverage Issue related to possible incorrect coverage and removed needs more info More details are needed labels May 14, 2020
@VenkateshSrini
Copy link
Author

@MarcoRossignoli ,
But that cannot be the way forward that I loose coverage with every async statement. We need to have a standard way out of this problem. What would be your suggestion in such cases?

@MarcoRossignoli
Copy link
Collaborator

Why are you using that attribute filter?What do you want to filter out?

@sac80644
Copy link

Glad I found this thread. I was just about to report this bug. ExcludeFromCodeCoverage attribute seems to work for non-async methods but not async in my case.

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented May 15, 2020

Thanks for the informations

@VenkateshSrini
Copy link
Author

@MarcoRossignoli ,
As you can see I want to exclude a few methods fro test coverage as I will not be able to write a proper test for these methods. The reason is they contain a complex inline LINQ query that could not be mocked. Also, those kinds of methods are tested in Functional tests and from coverage statistics. Hence I'm decorating my method with ExcludeFromCodeCovarge on async method.

@MarcoRossignoli
Copy link
Collaborator

@VenkateshSrini I understood I meant that you cannot use CompilerGenerated anymore as value for /p:ExcludeByAttribute because it will exclude also all async methods(unrelated to this bug on ExlcudeFromCodeCoverage), I saw it in your command line.

@VenkateshSrini
Copy link
Author

ok. So how should I go about this in the current scenario

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented May 16, 2020

I'm fixing, for the moment you could use partials and put method you don't want cover into it and filter out with exclude by filename https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#source-files.
Let me know if you want a PoC

@MarcoRossignoli
Copy link
Collaborator

Should be fixed, feel free to reopen if needed.

@romainf-ubi
Copy link

romainf-ubi commented May 25, 2023

Is it possible that [ExcludeFromCodeCoverage] only works with coverlet.msbuild package and not coverlet.collector?

@MarcoRossignoli
Copy link
Collaborator

Is it possible that [ExcludeFromCodeCoverage] only works with coverlet.msbuild package and not coverlet.collector?

Engine is the same so I expect same behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tenet-coverage Issue related to possible incorrect coverage
Projects
None yet
Development

No branches or pull requests

4 participants