Skip to content

[test-improver] test: add edge case tests for DoNotUseShadowingAnalyzer (MSTEST0036) - #9489

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/do-not-use-shadowing-edge-cases-1782689161-102818816e2c8919
Jun 29, 2026
Merged

[test-improver] test: add edge case tests for DoNotUseShadowingAnalyzer (MSTEST0036)#9489
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
test-assist/do-not-use-shadowing-edge-cases-1782689161-102818816e2c8919

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

DoNotUseShadowingAnalyzer (MSTEST0036) had 18 tests, but three distinct code paths in the analyzer's logic were completely untested:

Untested pathGuard
Multi-level inheritance — shadowing a grandparent member through an empty intermediate classGetBaseMembers while-loop walking all BaseType ancestors
Property with same name but different typeSymbolEqualityComparer.Default.Equals(propertySymbol.Type, basePropertySymbol.Type) guard in IsMemberShadowing
Field with same name as base fieldIsMemberShadowing returns false for IFieldSymbol (only IMethodSymbol and IPropertySymbol are handled)

Approach

Added three [TestMethod] entries to DoNotUseShadowingAnalyzerTests.cs:

TestWhat it covers
WhenTestClassShadowsGrandparentMemberThroughIntermediateClass_Diagnostic[TestClass]DerivedClass : IntermediateClass : GrandparentClass where only GrandparentClass declares Method() and DerivedClass redeclares it → GetBaseMembers walks through the empty IntermediateClass to find GrandparentClass.Method, diagnostic fires
WhenTestClassHasSamePropertyNameAsBaseClassButDifferentType_NoDiagnosticBase has int Property, derived has new string Property — types differ, SymbolEqualityComparer check returns false → no diagnostic
WhenTestClassHasSameFieldNameAsBaseClass_NoDiagnosticBase has int Field, derived has new int FieldIsMemberShadowing has no IFieldSymbol branch → falls through to return false → no diagnostic

Coverage Impact

BeforeAfter
Tests in DoNotUseShadowingAnalyzerTests1821

Trade-offs

Purely additive — no production code changes, no new dependencies.

Test Status

All 21/21 tests pass (net8.0, Debug):

Test run summary: Passed!
total: 21
failed: 0
succeeded: 21
duration: 4s 902ms

Reproducibility

.dotnet/dotnet test test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj \
-f net8.0 --no-build -c Debug \
--filter "FullyQualifiedName~DoNotUseShadowingAnalyzerTests"

🤖 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. · 868.9 AIC · ⌖ 24 AIC · ⊞ 58.1K · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

Three new tests covering untested paths in IsMemberShadowing and GetBaseMembers:
- WhenTestClassShadowsGrandparentMemberThroughIntermediateClass_Diagnostic:
GetBaseMembers walks the full inheritance chain; a TestClass method that
shadows a grandparent member (with an empty intermediate class) is detected.
- WhenTestClassHasSamePropertyNameAsBaseClassButDifferentType_NoDiagnostic:
IsMemberShadowing requires SymbolEqualityComparer equality on property types;
same name but different type (int vs string) is not considered shadowing.
- WhenTestClassHasSameFieldNameAsBaseClass_NoDiagnostic:
IsMemberShadowing handles IMethodSymbol and IPropertySymbol only; fields
(IFieldSymbol) fall through to 'return false', so field hiding is not flagged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
CopilotAI review requested due to automatic review settings June 28, 2026 23:32
@EvangelinkAmaury Levé (Evangelink) added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 28, 2026

CopilotAI 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

Adds targeted unit tests for the MSTest analyzers project to cover previously untested edge paths in DoNotUseShadowingAnalyzer (MSTEST0036), improving confidence in inheritance-walking and member-type handling behavior.

Changes:

  • Add a diagnostic test for shadowing a grandparent member through an empty intermediate base type.
  • Add no-diagnostic tests for (1) same property name with different type and (2) same field name as base field.
Show a summary per file
FileDescription
test/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.csAdds 3 new analyzer tests covering grandparent-member shadowing, property type mismatch, and field hiding scenarios.

Review details

  • Files reviewed: 1/1 changed files
  • Comments generated: 3
  • Review effort level: Low

Comment threadtest/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs Outdated
Comment threadtest/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs Outdated
Comment threadtest/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs Outdated
@EvangelinkAmaury Levé (Evangelink) added the state/needs-review Awaiting review from the team. label Jun 29, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review June 29, 2026 10:09
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
MemberAuthor

🧪 Test quality grade — PR #9489

ΔTestGradeBandNotes
newDoNotUseShadowingAnalyzerTests.
WhenTestClassHasSameFieldNameAsBaseClass_
NoDiagnostic
A90–100Clear single scenario; no-diagnostic assertion is idiomatic and complete for Roslyn analyzer tests.
newDoNotUseShadowingAnalyzerTests.
WhenTestClassHasSamePropertyNameAsBaseClassButDifferentType_
NoDiagnostic
A90–100No issues found.
newDoNotUseShadowingAnalyzerTests.
WhenTestClassShadowsGrandparentMemberThroughIntermediateClass_
Diagnostic
A90–100Diagnostic location marker asserts the full inheritance chain is checked; comment explains the scenario clearly.

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. · 173.8 AIC · ⌖ 14 AIC · ⊞ 43.7K · [◷]( · )

Copy link
Copy Markdown
MemberAuthor

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.

Review: PR #9489 — Edge case tests for DoNotUseShadowingAnalyzer (MSTEST0036)

This PR adds three test methods to cover previously untested code paths in DoNotUseShadowingAnalyzer. All three tests correctly reflect the analyzer's current behavior and are well-structured.

Dimension findings

#DimensionVerdict
17Documentation Accuracy🟡 2 MODERATE
18Analyzer & Code Fix Quality🟡 2 MODERATE (same findings)

✅ 20/22 dimensions clean.

  • Test 2 (WhenTestClassHasSamePropertyNameAsBaseClassButDifferentType_NoDiagnostic) — The comment says "not considered shadowing", which implies intentional design, but the production code has no corresponding explanation for why different-type same-name properties are excluded from the diagnostic. If intentional, the rationale should be documented in IsMemberShadowing; if a gap, a follow-up issue should be filed.
  • Test 3 (WhenTestClassHasSameFieldNameAsBaseClass_NoDiagnostic)GetBaseMembers collects IFieldSymbol members (they pass the skip filter), but IsMemberShadowing has no IFieldSymbol branch and returns false by fallthrough — no comment in the production code explains this omission. Same ask: document the intent or track the gap.

Correctness verification

All three new tests correctly exercise the claimed code paths:

TestPath verifiedVerdict
WhenTestClassShadowsGrandparentMemberThroughIntermediateClass_DiagnosticGetBaseMembers while-loop traverses IntermediateClass (no members), then GrandparentClass (finds Method) → diagnostic fires
WhenTestClassHasSamePropertyNameAsBaseClassButDifferentType_NoDiagnosticIsMemberShadowing property branch: SymbolEqualityComparer.Default.Equals(string, int)false → no diagnostic
WhenTestClassHasSameFieldNameAsBaseClass_NoDiagnosticIsMemberShadowing: neither method nor property branch matches IFieldSymbol → falls through to return false → no diagnostic

Minor observation (NIT)

The new test names (WhenTestClassShadows..., WhenTestClassHas...) don't follow the existing pattern in the file (WhenTestClassHave...). This is inconsistent but a very minor style nit that does not need to block the PR.

Assertion style

VerifyCS.VerifyAnalyzerAsync is the correct assertion mechanism for this project. BannedSymbols.txt bans AwesomeAssertions; no violations found.


The tests are functionally correct and a welcome addition to the suite. The inline comments above ask the team to clarify design intent vs. gap for the two NoDiagnostic cases — no code changes are strictly required to merge, but the clarification would improve long-term maintainability.

Comment threadtest/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs Outdated
Comment threadtest/UnitTests/MSTest.Analyzers.UnitTests/DoNotUseShadowingAnalyzerTests.cs Outdated
@Evangelink
Amaury Levé (Evangelink) merged commit 85c779f into mainJun 29, 2026
81 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the test-assist/do-not-use-shadowing-edge-cases-1782689161-102818816e2c8919 branch June 29, 2026 11:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state/needs-reviewAwaiting review from the team.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Evangelink@0101