You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[test-improver] test: MSTEST0029 — add edge case tests for virtual/override and make-private fixer #9758
Improve test coverage for PublicMethodShouldBeTestMethodAnalyzer (MSTEST0029) by closing three gaps in the existing test suite:
IsVirtual early-return path — the analyzer silently skips public virtual methods in a test class (line 70 of the analyzer). No test previously exercised a virtual method that does not implement an interface.
IsOverride early-return path — same gap for override methods (line 71 of the analyzer).
"Change to private" code fix — PublicMethodShouldBeTestMethodFixer offers two code fixes: 1 Add [TestMethod] and 2 Change accessibility to private. The second fix (CodeActionIndex = 1) was entirely untested.
Misleading existing test — WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic used [TestInitialize] in its body, making it a duplicate of the TestInitialize test and leaving the [TestCleanup] suppression path untested. Fixed the test body to use [TestCleanup].
Approach
All additions follow the existing test patterns in the file:
NoDiagnostic tests use VerifyCS.VerifyAnalyzerAsync (consistent with similar virtual/interface tests nearby).
The code-fix test uses new VerifyCS.Test { CodeActionIndex = 1 }.RunAsync() — the same pattern used in AvoidAssertAreEqualOnCollectionsAnalyzerTests for multi-fix scenarios.
Test run summary: Passed!
total: 19, failed: 0, succeeded: 19, skipped: 0
Trade-offs
These are pure test additions — no production code changed. Tests are straightforward with minimal maintenance burden.
🤖 Automated content by GitHub Copilot. Generated by the Test Improver workflow. · 414.4 AIC · ⌖ 19.1 AIC · ⊞ 13K · [◷]( · ◷)
Add this agentic workflows to your repo
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/test-improver.md@main
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch test-assist/mstest0029-edge-cases-007b062cf91cf3df.
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (137 of 137 lines)
From 533b74681ca68c7903cc0a19339dcb07c08d7f5b Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Wed, 8 Jul 2026 23:34:02 +0000
Subject: [PATCH] test: add MSTEST0029 edge cases for virtual/override and
make-private fixer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Add three new tests for PublicMethodShouldBeTestMethodAnalyzer (MSTEST0029):
1. WhenPublicVirtualMethodInTestClass_NoDiagnostic — exercises the IsVirtual
early-return path (line 70 in the analyzer). 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 (line 71 in the analyzer). 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 offered by
PublicMethodShouldBeTestMethodFixer. This fix was previously completely untested.
Also fix WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic: the test body was
using [TestInitialize] instead of [TestCleanup], making it a duplicate of the
WhenMethodIsPublicAndMarkedAsTestInitialize_NoDiagnostic test and leaving the
[TestCleanup] attribute path untested.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
...icMethodShouldBeTestMethodAnalyzerTests.cs | 84 ++++++++++++++++++-
1 file changed, 83 insertions(+), 1 deletion(-)
diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs
index 88c228e..14604b3 100644
--- a/test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs+++ b/test/UnitTests/MSTest.Analyzers.UnitTests/P
... (truncated)
Goal and Rationale
Improve test coverage for
PublicMethodShouldBeTestMethodAnalyzer(MSTEST0029) by closing three gaps in the existing test suite:IsVirtualearly-return path — the analyzer silently skips public virtual methods in a test class (line 70 of the analyzer). No test previously exercised a virtual method that does not implement an interface.IsOverrideearly-return path — same gap for override methods (line 71 of the analyzer).PublicMethodShouldBeTestMethodFixeroffers two code fixes: 1 Add[TestMethod]and 2 Change accessibility toprivate. The second fix (CodeActionIndex = 1) was entirely untested.WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnosticused[TestInitialize]in its body, making it a duplicate of theTestInitializetest and leaving the[TestCleanup]suppression path untested. Fixed the test body to use[TestCleanup].Approach
All additions follow the existing test patterns in the file:
VerifyCS.VerifyAnalyzerAsync(consistent with similarvirtual/interfacetests nearby).new VerifyCS.Test { CodeActionIndex = 1 }.RunAsync()— the same pattern used inAvoidAssertAreEqualOnCollectionsAnalyzerTestsfor multi-fix scenarios.Changes
test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs[TestInitialize]→[TestCleanup]inWhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnosticbodyWhenPublicVirtualMethodInTestClass_NoDiagnosticWhenPublicOverrideMethodInTestClass_NoDiagnosticWhenMethodIsPublicAndNotMarkedAsTestMethod_ChangeToPrivateFixTest Status
Build and all 19 PublicMethod* tests pass:
Trade-offs
These are pure test additions — no production code changed. Tests are straightforward with minimal maintenance burden.
Add this agentic workflows to your repo
To install this agentic workflow, run
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch
test-assist/mstest0029-edge-cases-007b062cf91cf3df.Click here to create the pull request
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (137 of 137 lines)