[test-improver] test: MSTEST0029 — add edge case tests for virtual/override and make-private fixer
type/test-gaptype/automationagentic-workflows
## Goal and Rationale
Improve test coverage for `PublicMethodShouldBeTestMethodAnalyzer` (MSTEST0029) by closing three gaps in the existing test suite:
1. **`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.
2. **`IsOverride` early-return path** — same gap for override methods (line 71 of the analyzer).
3. **"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.
4. **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.
## Changes
**`test/UnitTests/MSTest.Analyzers.UnitTests/PublicMethodShouldBeTestMethodAnalyzerTests.cs`**
- Fix: change `[TestInitialize]` → `[TestCleanup]` in `WhenMethodIsPublicAndMarkedAsTestCleanup_NoDiagnostic` body
- Add: `WhenPublicVirtualMethodInTestClass_NoDiagnostic`
- Add: `WhenPublicOverrideMethodInTestClass_NoDiagnostic`
- Add: `WhenMethodIsPublicAndNotMarkedAsTestMethod_ChangeToPrivateFix`
## Test Status
Build and all 19 PublicMethod* tests pass:
```
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](https://github.com/microsoft/testfx/actions/runs/28982412189/agentic_workflow) workflow. · 414.4 AIC · ⌖ 19.1 AIC · ⊞ 13K · [◷]( · [◷](https://github.com/search?q=repo%3Amicrosoft%2Ftestfx+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests))
>
<details>
<summary>Add this agentic workflows to your repo</summary>
To install this agentic workflow, run
```
gh aw add githubnext/agentics/workflows/test-improver.md@main
```
</details>
<!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, version: 1.0.65, model: claude-sonnet-4.6, id: 28982412189, workflow_id: test-improver, run: https://github.com/microsoft/testfx/actions/runs/28982412189 -->
<!-- gh-aw-workflow-id: test-improver -->
<!-- gh-aw-workflow-call-id: microsoft/testfx/test-improver -->
---
> [!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](https://github.com/microsoft/testfx/compare/main...test-assist/mstest0029-edge-cases-007b062cf91cf3df?expand=1&title=%5Btest-improver%5D%20test%3A%20MSTEST0029%20%E2%80%94%20add%20edge%20case%20tests%20for%20virtual%2Foverride%20and%20make-private%20fixer)**
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](https://github.github.com/gh-aw/reference/faq/#why-is-my-create-pull-request-workflow-failing-with-github-actions-is-not-permitted-to-create-or-approve-pull-requests)
<details><summary>Show patch preview (137 of 137 lines)</summary>
```diff
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)
```
</details>
0 条评论