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

Poor documentation around attribute-based exclusion #1591

Closed
richardissimo opened this issue Jan 17, 2024 · 2 comments · Fixed by #1603
Closed

Poor documentation around attribute-based exclusion #1591

richardissimo opened this issue Jan 17, 2024 · 2 comments · Fixed by #1603
Labels
documentation duplicate This issue or pull request already exists

Comments

@richardissimo
Copy link

I am trying to find somewhere in the documentation which states the default list of attributes that cause things to be excluded from coverage.

I'm guessing the answer is simply "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute", but I can't see that documented anywhere.

I'm using the "dotnet test" approach if that matters. I think the documentation for that is https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md

The only mention on there of anything close to this is the example which shows
Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute
but there is no explanation for what that does. For example, does that setting replace the default attributes that are used to exclude things, or does it just add to it?

I have read elsewhere that these are just the "name" of the attribute, without needing to be fully-qualified... it would be nice if that was documented here as well.

And I saw a comment somewhere saying don't forget the "Attribute" on the end. If that's true, if would be useful to have that here too, and if that's the case, then is the "Obsolete" example faulty?

@github-actions github-actions bot added the untriaged To be investigated label Jan 17, 2024
@daveMueller
Copy link
Collaborator

I'm guessing the answer is simply "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute", but I can't see that documented anywhere.

Yes you are right. We have written this down a bit more detailed here: docs
By default the ExcludeFromCodeCoverageAttribute can be used. If you want to use additional attributes for exclusion, you can use the ExcludeByAttribute property or the cli switch for the global tool (coverlet.console).

I'm using the "dotnet test" approach if that matters. I think the documentation for that is https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md

No matter what driver you are using you need to run the test at some point which is usually done by dotnet test. But I got what you mean, you are probably using coverlet.collector.

For example, does that setting replace the default attributes that are used to exclude things, or does it just add to it?

With this setting you can specify additional attributes for exclusion. So it just adds to it.

And I saw a comment somewhere saying don't forget the "Attribute" on the end. If that's true, if would be useful to have that here too, and if that's the case, then is the "Obsolete" example faulty?

You can specify the additional exclusion attributes with or without the postfix. This can be seen here: https://github.com/coverlet-coverage/coverlet/blob/master/src/coverlet.core/Instrumentation/Instrumenter.cs#L96

But only the type names without the namespaces, e.g. Coverlet.Custom.CodeAnalysis.CustomExcludeAttribute would not work but therefore CustomExcludeFromCodeCoverageAttribute and CustomExcludeFromCodeCoverage.

@daveMueller daveMueller added question This issue is a question and removed untriaged To be investigated labels Jan 18, 2024
@tonyhallett
Copy link
Contributor

But only the type names without the namespaces, e.g. Coverlet.Custom.CodeAnalysis.CustomExcludeAttribute would not work but therefore CustomExcludeFromCodeCoverageAttribute and CustomExcludeFromCodeCoverage.

#1589

@Bertk Bertk added documentation duplicate This issue or pull request already exists and removed question This issue is a question labels Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation duplicate This issue or pull request already exists
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants