[test-improver] test: add edge case tests for MemberConditionShouldBeValidAnalyzer (MSTEST0070)#9164
Conversation
…STEST0070) Add four missing edge cases: - WhenMethodIsInstance_MemberNotStatic: public instance method on condition type - WhenMethodIsInternalStatic_MemberNotPublic: internal static method not visible - WhenPropertyHasPrivateGetter_PropertyNotReadable: public static property with private getter - WhenParamsArrayWithConditionMode_MultipleInvalidMembers_AllReported: 4-arg ctor with ConditionMode + params string[] Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage for the MSTest analyzer MemberConditionShouldBeValidAnalyzer (MSTEST0070) by adding targeted edge-case tests for previously unexercised branches in ValidateMethod and ValidateProperty.
Changes:
- Add a test ensuring instance (non-static) methods trigger
MemberNotStaticRule. - Add a test ensuring non-public (internal) static methods trigger
MemberNotPublicRule. - Add a test ensuring properties with a non-public getter trigger
PropertyNotReadableRule. - Add a test ensuring the
(ConditionMode, Type, string, params string[])overload reports all invalid member names (multipleMemberNotFoundRulediagnostics).
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/MemberConditionShouldBeValidAnalyzerTests.cs | Adds 4 new edge-case analyzer tests covering method static/public checks, private getter readability, and multi-name validation for the params overload. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
🧪 Test quality grade — PR #9164
This advisory comment was generated automatically. Grades are heuristic
|
Evangelink
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
✅ 22/22 dimensions clean — no findings.
This is a pure test-only addition. All four new tests correctly target the code paths claimed in the PR description. Cross-checked against the analyzer source (MemberConditionShouldBeValidAnalyzer.cs):
| New test | Analyzer path exercised | Correctly specified? |
|---|---|---|
WhenMethodIsInstance_MemberNotStatic |
ValidateMethod → !method.IsStatic → MemberNotStaticRule |
✅ |
WhenMethodIsInternalStatic_MemberNotPublic |
ValidateMethod → DeclaredAccessibility != Public → MemberNotPublicRule |
✅ |
WhenPropertyHasPrivateGetter_PropertyNotReadable |
ValidateProperty → GetMethod.DeclaredAccessibility != Public (non-null getter, private accessibility) → PropertyNotReadableRule |
✅ |
WhenParamsArrayWithConditionMode_MultipleInvalidMembers_AllReported |
4-arg ctor parsed to memberNames = ["Missing1", "Missing2"]; both absent → two MemberNotFoundRule at #0 |
✅ |
The third test (WhenPropertyHasPrivateGetter_PropertyNotReadable) is meaningfully distinct from the existing WhenPropertyIsWriteOnly_PropertyNotReadable: the former exercises the GetMethod.DeclaredAccessibility != Accessibility.Public branch while the latter exercises the GetMethod is null branch — both arms of the same condition property.GetMethod is null || property.GetMethod.DeclaredAccessibility != Accessibility.Public.
The fourth test exercises the different Roslyn argument shapes for the 4-arg ctor: "Missing1" arrives as TypedConstantKind.Primitive while "Missing2" (the params element) arrives as a one-element TypedConstantKind.Array. The existing WhenAdditionalMembersAreInvalid_AllReported exercised the same parsing logic with the 3-arg ctor, but this confirms the 4-arg (ConditionMode + params) variant works identically.
One incidental gap that remains after this PR (not a requirement to fix here): ValidateMethod's first branch — method.MethodKind != MethodKind.Ordinary → MemberWrongKindRule — has no test. This path is difficult to trigger from normal C# source because non-ordinary methods (constructors, operators) aren't reachable via nameof in a way that feeds a [MemberCondition] attribute. Leaving it as a known untested edge case is reasonable.
All tests follow the existing file conventions (raw string literals, VerifyCS.VerifyAnalyzerAsync, marker-based location anchors), and the inline comments accurately describe the scenario being tested.
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review (on PR ready) workflow. · 365.9 AIC · ⌖ 13.1 AIC · ◷
Goal and Rationale
MemberConditionShouldBeValidAnalyzer(MSTEST0070) validates[MemberCondition]attributes and has 7 diagnostic rules. The existing tests covered the main happy/error paths but left four code paths untested inValidateMethodandValidateProperty.Approach
Added 4 targeted edge-case tests:
WhenMethodIsInstance_MemberNotStaticValidateMethod→!method.IsStaticMemberNotStaticRulefor methodsWhenMethodIsInternalStatic_MemberNotPublicValidateMethod→DeclaredAccessibility != PublicMemberNotPublicRulefor methodsWhenPropertyHasPrivateGetter_PropertyNotReadableValidateProperty→GetMethod.DeclaredAccessibility != PublicPropertyNotReadableRule(private getter, not fully write-only)WhenParamsArrayWithConditionMode_MultipleInvalidMembers_AllReported(ConditionMode, Type, string, params string[])+ both names invalidMemberNotFoundRule×2Previously,
MemberNotStaticRuleandMemberNotPublicRulewere only tested for properties and fields, not for methods. AndPropertyNotReadableRulewas only tested for a fully write-only property (no getter at all), not for a property with an existing-but-private getter.Trade-offs
Reproducibility
Test Status
✅ 25 tests passed (21 existing + 4 new), 0 failed.
Add this agentic workflows to your repo
To install this agentic workflow, run