Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Enable XUnit Analyzers - #38676

Merged
ViktorHofer merged 87 commits into
dotnet:masterfrom
ViktorHofer:CSharpXUnitAnalyzer
Jul 5, 2019
Merged

ViktorHofer merged 87 commits into
dotnet:masterfrom
ViktorHofer:CSharpXUnitAnalyzer

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Jun 19, 2019 •

Copy link
Copy Markdown
Member

Contributes to https://github.com/dotnet/corefx/issues/38677

I disabled the analyzer on five projects which need a bit more work:

  • src\System.Dynamic.Runtime\tests\System.Dynamic.Runtime.Tests.csproj
  • src\System.Linq.Expressions\tests\System.Linq.Expressions.Tests.csproj
  • src\System.Runtime.Extensions\tests\System.Runtime.Extensions.Tests.csproj
    ... and two private.xml ones

@ViktorHofer
ViktorHofer force-pushed the CSharpXUnitAnalyzer branch from 6222de7 to 1bea254 Compare June 19, 2019 12:32
@stephentoub

Copy link
Copy Markdown
Member

Most of these changes don't seem particularly valuable. Do we really need all of the rules enabled? The most important thing is ensuring that tests that should be run are run, which means all theories should have member/inline/etc. datas, and public parameterless void/Task methods should either be made private or be made [Fact]s/[Theory]s.

@ViktorHofer

ViktorHofer commented Jun 19, 2019 •

Copy link
Copy Markdown
Member Author

It's fairly easy to opt-out of analyzer rules. This can be applied per assembly or for multiple assemblies / repo wide.

The most important thing is ensuring that tests that should be run are run, which means all theories should have member/inline/etc. datas, and public parameterless void/Task methods should either be made private or be made [Fact]s/[Theory]s.

That's definitely something to watch out for but IMO not the only reason to enable the xunit analyzers. I can come up with a list of rules that might not offer much value (https://xunit.net/xunit.analyzers/rules/)

@stephentoub

stephentoub commented Jun 19, 2019 •

Copy link
Copy Markdown
Member

but IMO not the only reason to enable the xunit analyzers

Which others do you view as critically important?

I would rather we enable the "this is a test that should run but isn't" rules for all of corefx (I expect there are only a few violations, which we should be able to fix quickly), rather than delay rolling it out project by project, gated on addressing lots of minor quibbles.

@ViktorHofer

Copy link
Copy Markdown
Member Author

Which others do you view as critically important

I don't think this entire effort is critically important. Otherwise we would have a tracking issue that is set to 3.0. Therefore I'm not trying to find a quick solution here and I tend towards a black-listing approach.

I believe most of the errors make sense and should be enabled (https://xunit.net/xunit.analyzers/rules/):

Also I'm asking for uniformity here. Do we already have a ruleset defined somewhere for the dotnet organization that is considered as useful / do we have an exclusion list somewhere? It sounds like corefx is not the first repository that enables xunit analyzers.

@sharwell

Copy link
Copy Markdown

💡 xUnit1004 (Test methods should not be skipped) is handy to keep at severity Hidden. Hidden severity eliminates the message from the error list but keeps the ability to use the diagnostic's code fix to remove the Skip attribute. Setting it to None disables the diagnostic entirely so the code fix will not be available to use as a refactoring.

@stephentoub

stephentoub commented Jun 19, 2019 •

Copy link
Copy Markdown
Member

I don't think this entire effort is critically important.

There's a significant difference between:
a) Tests someone wrote that should be running but aren't.
b) Style quibbles.

I do think (a) is pretty darn important. It means things we expected to be tested aren't, and until we know what they are, we don't know whether they're critical or not.

Out of your list, to me that means we should just blanket enable:

  • xUnit1000
  • xUnit1003
  • xUnit1013

Many of the others are about catching at compile time what will otherwise be caught at runtime, e.g. xUnit1001 catches cases where a [Fact] has parameters, and that will today cause runtime failures. Would it be nice to catch at compile time instead? Yeah, it'd be nice. But it's not worth holding up the above for it. (That said, we should have 0 violations of these, exactly because they're checked at runtime.)

I would like to do this rather than doing it piecemeal, as this PR starts to do. If you don't want to do it or don't have time to, I'll do it. I'd be fine then if we wanted to incrementally enable the remainder of the rules.

@ViktorHofer
ViktorHofer force-pushed the CSharpXUnitAnalyzer branch from 1bea254 to 88a85ac Compare June 20, 2019 13:18
@ViktorHofer ViktorHofer changed the title Enable XUnit Analyzers for Microsoft.CSharp Enable XUnit Analyzers Jun 20, 2019
@ViktorHofer

Copy link
Copy Markdown
Member Author

@stephentoub as discussed I updated the PR and addressed the most important rules across the repo. I expect test failures as I enabled a lot of tests.

Comment thread src/CodeAnalysis.ruleset Resolved
@ViktorHofer
ViktorHofer force-pushed the CSharpXUnitAnalyzer branch from 88a85ac to 742714d Compare June 20, 2019 14:54
@stephentoub

Copy link
Copy Markdown
Member

(Please make sure to squash this all when merging.)

Comment thread src/Directory.Build.props Resolved
@ViktorHofer
ViktorHofer force-pushed the CSharpXUnitAnalyzer branch 8 times, most recently from d47f211 to 196c2ff Compare July 5, 2019 18:57
@ViktorHofer
ViktorHofer force-pushed the CSharpXUnitAnalyzer branch from 196c2ff to 283264e Compare July 5, 2019 19:48
@ViktorHofer ViktorHofer added this to the 3.0 milestone Jul 5, 2019
@ViktorHofer

Copy link
Copy Markdown
Member Author

This is ready to be squashed into master. I opened https://github.com/dotnet/corefx/issues/39233 for
follow-up work.

@ViktorHofer
ViktorHofer merged commit b8a7f34 into dotnet:master Jul 5, 2019
@ViktorHofer
ViktorHofer deleted the CSharpXUnitAnalyzer branch July 5, 2019 20:51
@stephentoub

Copy link
Copy Markdown
Member

Thanks, @ViktorHofer.

@ViktorHofer

ViktorHofer commented Jul 7, 2019 •

Copy link
Copy Markdown
Member Author

No need to thank me, we all care about test quality. I'm glad that we now have static analysis to capture wrong annotations.

macrogreg pushed a commit to open-telemetry/opentelemetry-dotnet-instrumentation that referenced this pull request Sep 24, 2020
* Enable XUnit Analyzers


Commit migrated from dotnet/corefx@b8a7f34
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Enable XUnit Analyzers


Commit migrated from dotnet/corefx@b8a7f34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants