Visitar URL original
Add ExcludeFromCodeCoverage attribute to templates by MattKotsenas · Pull Request #1854 · thomhurst/TUnit · GitHub
Skip to content

Add ExcludeFromCodeCoverage attribute to templates - #1854

Merged
thomhurst merged 3 commits into
thomhurst:mainfrom
MattKotsenas:feature/excludefromcodecoverage-template
Feb 15, 2025
Merged

thomhurst merged 3 commits into
thomhurst:mainfrom
MattKotsenas:feature/excludefromcodecoverage-template

Conversation

@MattKotsenas

Copy link
Copy Markdown
Contributor

Fixes #1853

This PR is operating under the principle that "defaults matter".

By default, code coverage tools calculate code coverage for all loaded assemblies, including the test assemblies themselves. This tends to artificially inflate the code coverage %, as the test code is included in the calculation. This behavior is often surprising to devs.

There's a mild consensus that test code shouldn't be included in % calculations (see https://about.codecov.io/blog/should-i-include-test-files-in-code-coverage-calculations and https://softwareengineering.stackexchange.com/questions/309015/when-does-it-make-sense-to-include-test-code-in-coverage as examples), and among devs that are calculating %, the prevailing method to do that appears to be setting [ExcludeFromCodeCoverage] on the test assembly (see https://github.com/search?q=%22assembly%3A+ExcludeFromCodeCoverage%22+language%3AC%23&type=code for some hits).

For this change I added the assembly attribute to the templates. This strikes a good balance of leading devs towards the Pit of Success, while letting them remove it if they disagree.

@MattKotsenas

Copy link
Copy Markdown
Contributor Author

Per the PR template, there don't appear to be any tests for the templates. If you want / need them let me know; the template tool provides https://github.com/dotnet/templating/blob/main/docs/authoring-tools/Templates-Testing-Tooling.md.

@thomhurst

Copy link
Copy Markdown
Owner

Per the PR template, there don't appear to be any tests for the templates. If you want / need them let me know; the template tool provides https://github.com/dotnet/templating/blob/main/docs/authoring-tools/Templates-Testing-Tooling.md.

If you've used that before and it's easy to implement I won't say no for tests to be added 😄

@thomhurst

Copy link
Copy Markdown
Owner

There's also a Playwright template

@MattKotsenas

Copy link
Copy Markdown
Contributor Author

Per the PR template, there don't appear to be any tests for the templates. If you want / need them let me know; the template tool provides https://github.com/dotnet/templating/blob/main/docs/authoring-tools/Templates-Testing-Tooling.md.

If you've used that before and it's easy to implement I won't say no for tests to be added 😄

#1863

Once that looks good to you and is merged I'll rebase this PR on top of that one

@MattKotsenas

Copy link
Copy Markdown
Contributor Author

There's also a Playwright template

I didn't add it initially because Playwright is more an integration test tool, so I would be surprised if code coverage was useful there at all?

That said, I think it's reasonable to keep the templates in sync with each other, so added to Playwright as well :)

@thomhurst
thomhurst enabled auto-merge (squash) February 15, 2025 20:38
@thomhurst
thomhurst merged commit b35490d into thomhurst:main Feb 15, 2025

This branch was previously deployed

1 inactive deployment
Pull Requests — 406aacdf Deployed Feb 15, 2025 by thomhurst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Set [ExcludeFromCodeCoverage] in templates

2 participants