Skip to content

[test-improver] test: add edge case tests for MemberConditionShouldBeValidAnalyzer (MSTEST0070)#9164

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/member-condition-edge-cases-8aa83e3b72afe1ec
Jun 16, 2026
Merged

[test-improver] test: add edge case tests for MemberConditionShouldBeValidAnalyzer (MSTEST0070)#9164
Evangelink merged 1 commit into
mainfrom
test-assist/member-condition-edge-cases-8aa83e3b72afe1ec

Conversation

@Evangelink

Copy link
Copy Markdown
Member

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 in ValidateMethod and ValidateProperty.

Approach

Added 4 targeted edge-case tests:

New test Code path exercised Rule
WhenMethodIsInstance_MemberNotStatic ValidateMethod!method.IsStatic MemberNotStaticRule for methods
WhenMethodIsInternalStatic_MemberNotPublic ValidateMethodDeclaredAccessibility != Public MemberNotPublicRule for methods
WhenPropertyHasPrivateGetter_PropertyNotReadable ValidatePropertyGetMethod.DeclaredAccessibility != Public PropertyNotReadableRule (private getter, not fully write-only)
WhenParamsArrayWithConditionMode_MultipleInvalidMembers_AllReported 4-arg ctor (ConditionMode, Type, string, params string[]) + both names invalid MemberNotFoundRule ×2

Previously, MemberNotStaticRule and MemberNotPublicRule were only tested for properties and fields, not for methods. And PropertyNotReadableRule was only tested for a fully write-only property (no getter at all), not for a property with an existing-but-private getter.

Trade-offs

  • Tests are straightforward and low-maintenance.
  • No new dependencies or test infrastructure.

Reproducibility

DOTNET_INSTALL_DIR=/usr/share/dotnet ./build.sh --restore
.dotnet/dotnet run --project test/UnitTests/MSTest.Analyzers.UnitTests --launch-profile "" -f net8.0 --no-build -c Debug -- --filter "ClassName~MemberConditionShouldBeValid"

Test Status

✅ 25 tests passed (21 existing + 4 new), 0 failed.

🤖 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 Test Improver workflow. · 1.6K AIC · ⌖ 23.4 AIC · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/test-improver.md@main

…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>
Copilot AI review requested due to automatic review settings June 15, 2026 23:44
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (multiple MemberNotFoundRule diagnostics).
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

@Evangelink Evangelink marked this pull request as ready for review June 16, 2026 03:43
@Evangelink

Copy link
Copy Markdown
Member Author

🧪 Test quality grade — PR #9164

ΔTestGradeBandNotes
new MemberConditionShouldBeValidAnalyzerTests.
WhenMethodIsInstance_
MemberNotStatic
A 90–100 No issues found.
new MemberConditionShouldBeValidAnalyzerTests.
WhenMethodIsInternalStatic_
MemberNotPublic
A 90–100 No issues found.
new MemberConditionShouldBeValidAnalyzerTests.
WhenParamsArrayWithConditionMode_
MultipleInvalidMembers_
AllReported
A 90–100 Two diagnostics asserted covering both params elements; comments document the 4-arg overload under test.
new MemberConditionShouldBeValidAnalyzerTests.
WhenPropertyHasPrivateGetter_
PropertyNotReadable
A 90–100 Comment documents why the scenario is non-obvious (private getter on a public property).

This advisory comment was generated automatically. Grades are heuristic
and informational — they do not block merging. Re-run with
/grade-tests.

🤖 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 Grade Tests on PR (on open / sync) workflow. · 199 AIC · ⌖ 13.5 AIC · [◷]( · )

@Evangelink Evangelink left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.IsStaticMemberNotStaticRule
WhenMethodIsInternalStatic_MemberNotPublic ValidateMethodDeclaredAccessibility != PublicMemberNotPublicRule
WhenPropertyHasPrivateGetter_PropertyNotReadable ValidatePropertyGetMethod.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.OrdinaryMemberWrongKindRule — 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 ·

@Evangelink Evangelink enabled auto-merge (squash) June 16, 2026 07:02
@Evangelink Evangelink disabled auto-merge June 16, 2026 07:59
@Evangelink Evangelink merged commit 916c796 into main Jun 16, 2026
56 checks passed
@Evangelink Evangelink deleted the test-assist/member-condition-edge-cases-8aa83e3b72afe1ec branch June 16, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants