test: MSTEST0029 — add edge case tests for virtual/override and make-private fixer - #9785
Conversation
… fixer Add three new tests for PublicMethodShouldBeTestMethodAnalyzer (MSTEST0029): 1. WhenPublicVirtualMethodInTestClass_NoDiagnostic - exercises the IsVirtual early-return path. A public virtual method in a [TestClass] that does not implement any interface should produce no diagnostic. 2. WhenPublicOverrideMethodInTestClass_NoDiagnostic - exercises the IsOverride early-return path. A public override of a non-interface base-class method in a [TestClass] should produce no diagnostic. 3. WhenMethodIsPublicAndNotMarkedAsTestMethod_ChangeToPrivateFix - exercises CodeActionIndex=1, the 'Change accessibility to private' code fix. Also fix WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic: the test body was using [TestInitialize] instead of [TestCleanup]. Fixes #9758 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves unit-test coverage for PublicMethodShouldBeTestMethodAnalyzer (MSTEST0029) by closing three gaps in PublicMethodShouldBeTestMethodAnalyzerTests.cs and correcting one misleading existing test. It is a test-only change with no production code touched. The additions correctly target the analyzer's IsVirtual/IsOverride early-return branches and the fixer's previously-untested "change accessibility to private" code action.
Changes:
- Adds
WhenPublicVirtualMethodInTestClass_NoDiagnosticandWhenPublicOverrideMethodInTestClass_NoDiagnosticto cover the analyzer's virtual/override suppression paths. - Adds
WhenMethodIsPublicAndNotMarkedAsTestMethod_ChangeToPrivateFixto cover the fixer's second code action (CodeActionIndex = 1). - Fixes
WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnosticto actually use[TestCleanup]instead of[TestInitialize], so the cleanup suppression path is genuinely exercised.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs | Adds three new tests (virtual, override, change-to-private fixer) and corrects the [TestCleanup] test body; all consistent with existing verifier patterns and diagnostic-location conventions. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Medium
This comment has been minimized.
This comment has been minimized.
🔍 Build Failure AnalysisSummary — The build fails because two new Root cause: Undeclared internal API members (RS0051)The The failure in Affected symbols
Proposed fix Add the following two lines to #nullable enable
+static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.ReadFields(System.IO.Stream! stream, System.Func<ushort, int, bool>! tryReadField) -> void
+static Microsoft.Testing.Platform.IPC.Serializers.BaseSerializer.WriteListPayload<T>(System.IO.Stream! stream, ushort fieldId, T[]? list, System.Action<System.IO.Stream!, T>! writeItem) -> void
Impact on this PR: This PR only adds test cases to Build overview
All MSBuild errors (7)
🤖 Generated by the Build Failure Analysis workflow using (a href="(dev.azure.com/redacted) · commit 2839244
|
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
✅ 22/22 dimensions clean — no findings.
Applicable dimensions verified (all clean): Algorithmic Correctness, Test Isolation, Assertion Quality, Test Completeness, Code Structure, Naming & Conventions, Analyzer & Code Fix Quality, Scope & PR Discipline.
N/A dimensions (test-only PR, no production code): Threading, Security, Public API, Performance, Cross-TFM, Resource Management, Defensive Coding, Localization, Flakiness, Data-Driven, Documentation, IPC Wire, Build Infrastructure, PowerShell.
Notes:
- The
[TestInitialize]→[TestCleanup]fix correctly eliminates a duplicate of the TestInitialize test and restores coverage of thetestCleanupAttributeSymbolsuppression path. - The new virtual/override tests appropriately use
VerifyCS.VerifyAnalyzerAsync(analyzer-only verification) since these paths produce no diagnostic and no code-fix action is relevant. - The
CodeActionIndex = 1test correctly exercises the second registered code action (ChangeMethodAccessibilityToPrivateFix) from the fixer.
🧪 Test quality grade — PR #9785
This advisory comment was generated automatically. Grades are heuristic
|
Fixes #9758.
Improves test coverage for
PublicMethodShouldBeTestMethodAnalyzer(MSTEST0029) by closing gaps in the existing test suite.Changes
test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.csWhenPublicVirtualMethodInTestClass_NoDiagnostic— exercises theIsVirtualearly-return path: a public virtual method in a[TestClass]that does not implement any interface should produce no diagnostic.WhenPublicOverrideMethodInTestClass_NoDiagnostic— exercises theIsOverrideearly-return path: a public override of a non-interface base-class method in a[TestClass]should produce no diagnostic.WhenMethodIsPublicAndNotMarkedAsTestMethod_ChangeToPrivateFix— exercisesCodeActionIndex = 1, the "Change accessibility to private" code fix offered byPublicMethodShouldBeTestMethodFixer, which was previously untested.WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic— the test body used[TestInitialize]instead of[TestCleanup], making it a duplicate of theTestInitializetest and leaving the[TestCleanup]suppression path untested.Test status
Pure test additions — no production code changed. All 19
PublicMethodShouldBeTestMethodAnalyzerTestspass: