Skip to content

[test-improver] test: add edge case tests for DoNotStoreStaticTestContextAnalyzer#8809

Draft
Evangelink wants to merge 1 commit into
mainfrom
test-assist/donotstorestatictestcontext-edge-cases-26bf763dab1005b1
Draft

[test-improver] test: add edge case tests for DoNotStoreStaticTestContextAnalyzer#8809
Evangelink wants to merge 1 commit into
mainfrom
test-assist/donotstorestatictestcontext-edge-cases-26bf763dab1005b1

Conversation

@Evangelink
Copy link
Copy Markdown
Member

🤖 Test Improver — automated AI assistant focused on improving tests for this repository.

Goal and Rationale

DoNotStoreStaticTestContextAnalyzer (MSTEST0024) had only 2 tests: one happy path (diagnostic) and one no-diagnostic case. The analyzer's logic has several distinct conditions (Instance: null for static members, IParameterReferenceOperation for the value type) that each deserve coverage to prevent regressions.

Approach

Added four new tests that each probe a specific condition the analyzer checks:

Test What it verifies
WhenAssigningToInstanceMember_NoDiagnostic Instance field/property assignments are not flagged (the Instance: null guard)
WhenAssigningToLocalVariable_NoDiagnostic Local variable assignments (not IMemberReferenceOperation) are not flagged
WhenAssigningNonTestContextParameterToStaticField_NoDiagnostic Only TestContext parameters are flagged — other types assigned to static fields are fine
WhenAssigningTestContextInHelperMethod_Diagnostic The diagnostic fires regardless of which method the assignment appears in — any static member assignment of a TestContext parameter is flagged

Coverage Impact

These tests cover the four logical branches in AnalyzeOperation:

  • The Instance: null check (both true and false paths)
  • The IParameterReferenceOperation check (both true and false paths)

Trade-offs

Minimal maintenance burden — tests are straightforward analyzer verifications with no external dependencies.

Reproducibility

./build.sh -test --projects "$(pwd)/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj"

Test Status

✅ All tests passed (0 errors, 0 warnings)

Generated by Test Improver · sonnet46 1.8M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

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

Add four new tests covering:
- Assigning TestContext to instance field/property (no diagnostic)
- Assigning TestContext parameter to local variable (no diagnostic)
- Assigning non-TestContext parameter to static field (no diagnostic)
- Assigning TestContext in a helper (non-lifecycle) method (diagnostic)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 3, 2026 23:36
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 3, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds additional unit tests for DoNotStoreStaticTestContextAnalyzer (MSTEST0024) in MSTest.Analyzers.UnitTests to increase coverage of edge cases around the analyzer’s OperationKind.SimpleAssignment logic and its pattern-matching conditions (Target static member + Value TestContext parameter).

Changes:

  • Adds new no-diagnostic tests intended to cover instance-member assignments, non-member targets, and non-TestContext assignments.
  • Adds a new diagnostic test ensuring the analyzer also fires when the static assignment occurs in a helper method.
Show a summary per file
File Description
test/UnitTests/MSTest.Analyzers.UnitTests/DoNotStoreStaticTestContextAnalyzerTests.cs Adds several new edge-case tests for MSTEST0024 analyzer behavior.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 3

Comment on lines +149 to +160
[ClassInitialize]
public static void ClassInit(TestContext tc)
{
}

[TestInitialize]
public void TestInit()
{
_testContext = TestContext;
TestContext = TestContext;
}
}
Comment on lines +179 to +180
TestContext local = tc;
local.WriteLine("");
Comment on lines +200 to +205
[AssemblyInitialize]
public static void AssemblyInit(TestContext tc)
{
s_name = "value";
}
}
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