[test-improver] test: add edge case tests for UseConditionBaseWithTestClassAnalyzer (MSTEST0041)#9103
Draft
Evangelink wants to merge 1 commit into
Draft
Conversation
…MSTEST0041) Add three targeted unit tests that exercise untested code paths: - WhenNonTestClassHasMultipleConditionAttributes_SingleDiagnostic: verifies FirstOrDefault behavior - only one diagnostic fires when a non-test class has two ConditionBase attributes (e.g. [OSCondition] + [CICondition]). - WhenAbstractNonTestClassHasConditionAttribute_Diagnostic: confirms no abstract-class exemption exists; abstract classes without [TestClass] still trigger the diagnostic. - WhenTwoLevelDerivedConditionAttributeOnNonTestClass_Diagnostic: confirms Inherits() is recursive - a 2nd-level ConditionBase subclass attribute on a non-test class still fires the diagnostic. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the MSTest analyzer unit tests for MSTEST0041 (UseConditionBaseWithTestClassAnalyzer) to cover previously untested analyzer behaviors, without modifying production analyzer logic.
Changes:
- Added a test ensuring that multiple
ConditionBaseAttribute-derived attributes on a non-test class produce a single diagnostic (matching the analyzer’sFirstOrDefaultbehavior). - Added a test confirming that an abstract non-test class with a condition attribute still triggers the diagnostic (no abstract exemption).
- Added a test confirming the condition-attribute detection works for a two-level derived condition attribute (recursive
Inherits()).
Show a summary per file
| File | Description |
|---|---|
test/UnitTests/MSTest.Analyzers.UnitTests/UseConditionBaseWithTestClassAnalyzerTests.cs |
Adds three focused test cases covering multi-attribute, abstract-class, and two-level-inheritance scenarios for MSTEST0041. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
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.
Goal and Rationale
UseConditionBaseWithTestClassAnalyzer(MSTEST0041) flags classes that have aConditionBaseAttributesubclass (e.g.[OSCondition],[CICondition], custom conditions) but are not marked as[TestClass]. Three code paths were untested:Multiple condition attributes on a non-test class — the analyzer uses
FirstOrDefault, so only one diagnostic fires regardless of how manyConditionBaseattributes are present. The message uses the first attribute's name.Abstract class without
[TestClass]— unlike some other analyzers in this repo,UseConditionBaseWithTestClassAnalyzerhas no abstract-class exemption. An abstract class with a condition attribute but no[TestClass]should trigger the diagnostic.Two-level derived condition attribute — the
Inherits()check is recursive. An attribute that is a 2nd-level subclass ofConditionBaseAttributeshould still trigger the diagnostic on a non-test class.Approach
Added three new
[TestMethod]test cases toUseConditionBaseWithTestClassAnalyzerTests.cs:WhenNonTestClassHasMultipleConditionAttributes_SingleDiagnostic— verifiesFirstOrDefaultbehavior: one diagnostic, named after the first attribute.WhenAbstractNonTestClassHasConditionAttribute_Diagnostic— confirms no abstract exemption exists in this analyzer.WhenTwoLevelDerivedConditionAttributeOnNonTestClass_Diagnostic— confirmsInherits()is recursive for condition attribute detection.Test Status
✅ All 12 tests pass (
MSTest.Analyzers.UnitTests, net8.0, Debug — 9 original + 3 new).Reproducibility
Trade-offs
Add this agentic workflows to your repo
To install this agentic workflow, run