Skip to content

[test-improver] test: add edge case tests for UseConditionBaseWithTestClassAnalyzer (MSTEST0041)#9103

Draft
Evangelink wants to merge 1 commit into
mainfrom
test-assist/useConditionBase-edge-cases-706f3df2ebd15a21
Draft

[test-improver] test: add edge case tests for UseConditionBaseWithTestClassAnalyzer (MSTEST0041)#9103
Evangelink wants to merge 1 commit into
mainfrom
test-assist/useConditionBase-edge-cases-706f3df2ebd15a21

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Goal and Rationale

UseConditionBaseWithTestClassAnalyzer (MSTEST0041) flags classes that have a ConditionBaseAttribute subclass (e.g. [OSCondition], [CICondition], custom conditions) but are not marked as [TestClass]. Three code paths were untested:

  1. Multiple condition attributes on a non-test class — the analyzer uses FirstOrDefault, so only one diagnostic fires regardless of how many ConditionBase attributes are present. The message uses the first attribute's name.

  2. Abstract class without [TestClass] — unlike some other analyzers in this repo, UseConditionBaseWithTestClassAnalyzer has no abstract-class exemption. An abstract class with a condition attribute but no [TestClass] should trigger the diagnostic.

  3. Two-level derived condition attribute — the Inherits() check is recursive. An attribute that is a 2nd-level subclass of ConditionBaseAttribute should still trigger the diagnostic on a non-test class.

Approach

Added three new [TestMethod] test cases to UseConditionBaseWithTestClassAnalyzerTests.cs:

  • WhenNonTestClassHasMultipleConditionAttributes_SingleDiagnostic — verifies FirstOrDefault behavior: one diagnostic, named after the first attribute.
  • WhenAbstractNonTestClassHasConditionAttribute_Diagnostic — confirms no abstract exemption exists in this analyzer.
  • WhenTwoLevelDerivedConditionAttributeOnNonTestClass_Diagnostic — confirms Inherits() is recursive for condition attribute detection.

Test Status

Test run summary: Passed!
  total: 12
  failed: 0
  succeeded: 12
  skipped: 0
  duration: 7s 141ms

✅ All 12 tests pass (MSTest.Analyzers.UnitTests, net8.0, Debug — 9 original + 3 new).

Reproducibility

./build.sh --restore   # first run only
.dotnet/dotnet test test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj \
  -f net8.0 --no-build -c Debug \
  --filter "ClassName=MSTest.Analyzers.Test.UseConditionBaseWithTestClassAnalyzerTests"

Trade-offs

  • Tests exercise existing code paths only — no production changes, no maintenance burden beyond the tests.
  • Each test documents a specific invariant of the analyzer (FirstOrDefault behavior, no abstract guard, recursive Inherits check).

🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Test Improver workflow. · 1K AIC · ⌖ 24.6 AIC · [◷]( · )

Add this agentic workflows to your repo

To install this agentic workflow, run

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

…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>
Copilot AI review requested due to automatic review settings June 13, 2026 23:36
@Evangelink Evangelink added type/automation Created or maintained by an agentic workflow. type/test-gap Missing or insufficient tests. labels Jun 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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’s FirstOrDefault behavior).
  • 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

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