[test-improver] test: add edge case tests for NonNullableReferenceNotInitializedSuppressor#8837
Merged
Evangelink merged 1 commit intoJun 5, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
TestContextproperty 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
JanKrivanek
approved these changes
Jun 5, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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'sReportSuppressionsmethod has three independent guard conditions that must all be true to suppress a CS8618 diagnostic:"TestContext"TestContext(exact type match viaSymbolEqualityComparer)[TestClass]or a derived attribute (viaInherits())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:
TestContextPropertyOnClassWithDerivedTestClassAttribute_DiagnosticIsSuppressed[TestClass]attribute triggers suppression viaInherits()TestContextPropertyWithWrongTypeName_DiagnosticIsNotSuppressedTestContextof a different type is not suppressedTestContextPropertyWithWrongPropertyName_DiagnosticIsNotSuppressedTestContexttype but namedMyContextis not suppressedTrade-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)Add this agentic workflows to your repo
To install this agentic workflow, run