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

Question about code coverage of test assemblies #1571

Closed
sungam3r opened this issue Dec 25, 2023 · 7 comments
Closed

Question about code coverage of test assemblies #1571

sungam3r opened this issue Dec 25, 2023 · 7 comments
Labels
question This issue is a question waiting for customer Waiting for customer action

Comments

@sungam3r
Copy link

Hi. I know that coverlet excludes test assemblies by default thanks to default value for IncludeTestAssembly setting. Nevertheless I've noticed that in some test reports for projects in our codebase there are still test assemblies like Company.CoolFeature.UnitTests. After investigation I found that this test assembly is referenced by another test assembly from repo. Why? Well, for example, because Company.CoolFeature.UnitTests shares some test models to use across test assemblies. So my questions are:

  1. Is this behavior expected or a some sort of bug?
  2. Does IncludeTestAssembly work only for "root" test assemblies and not for referenced ones?
  3. What is the recommended way to 100% exclude test assemblies from our code coverage?

Thanks.

@github-actions github-actions bot added the untriaged To be investigated label Dec 25, 2023
@Bertk Bertk added question This issue is a question and removed untriaged To be investigated labels Jan 13, 2024
@Bertk
Copy link
Collaborator

Bertk commented Jan 13, 2024

Hi, there are some limitations e.q. generated code for test projects.

You can use /p:ExcludeByAttribute="GeneratedCodeAttribute" and reduce the noise. I use reportgenerator and generate coverage reports. This can be used to tweak the configuration for the coverage reports.

see also coverlet CI:

<ExcludeByAttribute>Obsolete,GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>

@sungam3r
Copy link
Author

I have nothing to do with GeneratedCodeAttribute. One test assembly references other test assembly - that is all.

@Bertk
Copy link
Collaborator

Bertk commented Jan 13, 2024

Please provide more details. In the past we had similar issues and some were created by Microsoft.Net.Test.Sdk code generation.
You should also check the filter option see ReportGenerator Command Line Parameter

@sungam3r
Copy link
Author

sungam3r commented Jan 13, 2024

I know about report generator and use it. The question is about coverlet behaviour, not reportgenerator. What details I can provide? I already said that situation is very simple - when one test project become reference other test project then I see coverage for referenced assembly even when it was excluded by filter like [*Tests]*. If I remove reference then filter works as expected.

@Bertk
Copy link
Collaborator

Bertk commented Jan 13, 2024

Sorry, but could you please explain the target element for the filter e.g. file names will not work.

example exclude filter used in coverlet CI

/p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.xunit.extensions]*%2c[coverlet.tests.projectsample]*%2c[testgen_]*"

@daveMueller
Copy link
Collaborator

daveMueller commented Feb 1, 2024

@sungam3r I think this comment here explains it (#1503 (comment)).

  1. Is this behavior expected or a some sort of bug?

Yes it is the expected behavior.

  1. Does IncludeTestAssembly work only for "root" test assemblies and not for referenced ones?

Yes exactly. It only works for the test assembly being executed. If the root-(test)-assembly references other assemblies we can't really distinguish whether it is a test assembly or not.

  1. What is the recommended way to 100% exclude test assemblies from our code coverage?

It may be best for your scenario to exclude the assembly with the test models by using filters. The other option would be to really separate the test assemblies in a way that they don't reference each other.

Have I been able to clarify all questions?

@daveMueller daveMueller added the waiting for customer Waiting for customer action label Feb 1, 2024
@sungam3r
Copy link
Author

sungam3r commented Feb 2, 2024

@daveMueller Thank you, this is exactly what I expected to hear. I had to make sure that coverlet works just like that.

@sungam3r sungam3r closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question This issue is a question waiting for customer Waiting for customer action
Projects
None yet
Development

No branches or pull requests

3 participants