Repository navigation
Consider inherited test methods when detecting test classes (CA1515 suppressor, xUnit1056) - #233
Merged
bradwilson merged 2 commits intoSep 16, 2026
Conversation
…uppressor, xUnit1056) IsTestClassNonStrict only looked at the type's own members, so a concrete class whose test methods were all inherited from a base class was not recognized as a test class. The CA1515 suppressor therefore left the warning on the class xUnit actually runs.
Member
|
Thanks! |
Member
|
Available in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
IsTestClassNonStrictonly inspectedtype.GetMembers(), ignoring base types. A concrete class whose test methods are all inherited was not recognized as a test class:The CA1515 suppressor (
MakeTypesInternalSuppressor) suppressed the warning onBaseTestsbut still reported it onDerivedTests— the class xUnit actually runs, which must be public.Fix
IsTestClassNonStrictnow usesGetInheritedAndOwnMembers(), so inherited[Fact]/[Theory]methods are taken into account. The abstract base class remains suppressed as well (it cannot be made internal while a public test class derives from it — CS0060).Reviewer notes
The non-strict check is also used by xUnit1056 (
TypeMustHaveSinglePublicConstructor). With this change, a class that inherits its tests and declares multiple public constructors is now flagged, which is correct since xUnit cannot construct it.Tests
Both new scenarios fail without the fix; the full test suite passes on net8.0.