Skip to content

[test-improver] test: add edge case tests for NonNullableReferenceNotInitializedSuppressor#8837

Merged
Evangelink merged 1 commit into
mainfrom
test-assist/nonnullable-suppressor-edge-cases-6dfc399e97093649
Jun 5, 2026
Merged

[test-improver] test: add edge case tests for NonNullableReferenceNotInitializedSuppressor#8837
Evangelink merged 1 commit into
mainfrom
test-assist/nonnullable-suppressor-edge-cases-6dfc399e97093649

Conversation

@Evangelink
Copy link
Copy Markdown
Member

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

Goal and Rationale

NonNullableReferenceNotInitializedSuppressor (MSTEST0028) had only 3 tests, each covering the positive "suppress" path or the basic "don't suppress" path. The suppressor's ReportSuppressions method has three independent guard conditions that must all be true to suppress a CS8618 diagnostic:

  1. Property name must be "TestContext"
  2. Property type must be TestContext (exact type match via SymbolEqualityComparer)
  3. Containing type must have [TestClass] or a derived attribute (via Inherits())

Previously only condition 3 was tested via the "non-test-class" case. Conditions 1 and 2 had no dedicated "fail" path tests, and condition 3 was only tested with the base [TestClass] attribute (not a derived one).

Approach

Added four new tests:

Test Condition exercised
TestContextPropertyOnClassWithDerivedTestClassAttribute_DiagnosticIsSuppressed Condition 3 (positive): derived [TestClass] attribute triggers suppression via Inherits()
TestContextPropertyWithWrongTypeName_DiagnosticIsNotSuppressed Condition 2 (negative): a class named TestContext of a different type is not suppressed
TestContextPropertyWithWrongPropertyName_DiagnosticIsNotSuppressed Condition 1 (negative): a property of TestContext type but named MyContext is not suppressed

Trade-offs

Minimal maintenance burden — tests are straightforward suppressor verifications.

Reproducibility

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

Test Status

✅ All tests passed (0 errors, 0 warnings, net8.0)

Generated by Test Improver · sonnet46 5.3M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

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

…essor

Cover three logical conditions in AnalyzeSymbol that were previously untested:
1. Derived [TestClass] attribute - verifies the Inherits() check fires correctly
2. Property with wrong type (not TestContext) named 'TestContext' - verifies type check
3. Property named differently (not 'TestContext') of TestContext type - verifies name check

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 23:33
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 4, 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 NonNullableReferenceNotInitializedSuppressor (MSTEST0028) in MSTest.Analyzers.UnitTests, expanding coverage of suppression guard conditions (derived [TestClass] attributes, wrong property name, and wrong property type).

Changes:

  • Add a new test that validates suppression when [TestClass] is applied via a derived attribute.
  • Add negative tests ensuring suppression does not occur when the TestContext property has the wrong type or the wrong property name.
  • Extend expected diagnostic verification to cover the “wrong property name” case with correct CS8618 arguments.
Show a summary per file
File Description
test/UnitTests/MSTest.Analyzers.UnitTests/NonNullableReferenceNotInitializedSuppressorTests.cs Adds new edge-case unit tests for MSTEST0028 suppression behavior and strengthens negative-path coverage.

Copilot's findings

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

@Evangelink Evangelink marked this pull request as ready for review June 5, 2026 07:27
@Evangelink Evangelink enabled auto-merge (squash) June 5, 2026 07:28
@Evangelink Evangelink merged commit a4dc99a into main Jun 5, 2026
38 checks passed
@Evangelink Evangelink deleted the test-assist/nonnullable-suppressor-edge-cases-6dfc399e97093649 branch June 5, 2026 08:38
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.

3 participants