Skip to content

Quality Report: New Collection Assert API β€” Analyzer Coverage & Documentation GapsΒ #8338

@Evangelink

Description

@Evangelink

🎯 Repository Quality Improvement Report β€” New Assert API Analyzer Coverage

Analysis Date: 2026-05-18
Focus Area: New Collection Assert API β€” Analyzer Guidance and Documentation Completeness
Strategy Type: Custom (repository-specific)

Executive Summary

MSTest's Assert class has gained a rich set of new collection-oriented APIs β€” AreAllDistinct, AreAllNotNull, AreAllOfType, ContainsAll, DoesNotContainAll, AreEquivalent, AreNotEquivalent (22 entries in PublicAPI.Unshipped.txt) β€” which represent a major quality-of-life improvement for test authors. However, the UseProperAssertMethodsAnalyzer (MSTEST0037), which guides developers toward these better assertion methods, does not yet cover the new APIs. This means users writing verbose Assert.IsTrue(...) workarounds for collection-wide checks miss out on automated guidance toward the cleaner, more descriptive new methods.

Additionally, the main analyzer file UseProperAssertMethodsAnalyzer.cs has grown to 1 567 lines β€” by far the largest non-test source file β€” and warrants structural review. Closing the gap between the new APIs and the analyzer that promotes them will maximize the discoverability and adoption of these improvements.

Full Analysis Report

Focus Area: New Collection Assert API β€” Analyzer Guidance and Documentation Completeness

Current State Assessment

Metrics Collected:

Metric Value Status
New public API entries (Unshipped) 22 ⚠️ Needs analyzer coverage
UseProperAssertMethodsAnalyzer.cs lines 1 567 ⚠️ Oversized, hard to maintain
Analyzer files in MSTest.Analyzers/ 59 βœ… Healthy set
TODO/FIXME comments (source) 75 ⚠️ Review for actionability
Test-to-source file ratio 583 / 2 281 β‰ˆ 26 % ⚠️ Moderate coverage

Findings

Strengths

  • UseProperAssertMethodsAnalyzer (MSTEST0037) already guides toward IsNull, AreEqual, IsFalse, IsEmpty, ContainsSingle, Contains, comparison operators, and LINQ .Any() / .Count() β€” excellent baseline.
  • New Assert collection APIs are well-documented inline (every public method has XML <summary> in source).
  • Analyzer suite is active and growing (MSTEST0058–MSTEST0063 added recently).

Areas for Improvement

  • [High] MSTEST0037 does not yet suggest AreAllDistinct, ContainsAll, DoesNotContainAll, AreAllNotNull, AreAllOfType, AreEquivalent / AreNotEquivalent for common verbose patterns.
  • [Medium] UseProperAssertMethodsAnalyzer.cs is 1 567 lines; difficult to navigate and review. Similar refactoring was done for other large analyzers.
  • [Medium] No dedicated documentation page exists in docs/ for the new collection assertion APIs (only docs/Changelog.md entries).
  • [Low] 75 TODO/FIXME comments in source β€” periodic triage would catch stale items.

πŸ€– Suggested Improvement Tasks

Task 1: Extend MSTEST0037 to cover new collection assertion methods

Priority: High
Estimated Effort: Medium

The UseProperAssertMethodsAnalyzer should detect patterns such as:

Verbose pattern Suggested replacement
Assert.IsTrue(collection.Distinct().SequenceEqual(collection)) Assert.AreAllDistinct(collection)
Assert.IsTrue(expected.All(x => collection.Contains(x))) Assert.ContainsAll(expected, collection)
Assert.IsTrue(collection.All(x => x != null)) Assert.AreAllNotNull(collection)
Assert.IsTrue(collection.All(x => x is T)) Assert.AreAllOfType<T>(collection)

Files to modify:

  • src/Analyzers/MSTest.Analyzers/UseProperAssertMethodsAnalyzer.cs
  • src/Analyzers/MSTest.Analyzers.CodeFixes/UseProperAssertMethodsAnalyzerFixer.cs
  • src/Analyzers/MSTest.Analyzers/Resources.resx (new message strings; build to regenerate .xlf)
  • Corresponding test file in test/UnitTests/MSTest.Analyzers.UnitTests/

Task 2: Split UseProperAssertMethodsAnalyzer.cs into focused partial-class files

Priority: Medium
Estimated Effort: Medium

At 1 567 lines, UseProperAssertMethodsAnalyzer.cs is the largest source file in the repository and handles many independent detection scenarios. Refactor it into partial-class files grouped by assertion category (null checks, equality, collection membership, comparison, string), following the same pattern used in the Assert source files (Assert.Contains.cs, Assert.AreEqual.cs, etc.).

Suggested split:

  • UseProperAssertMethodsAnalyzer.NullChecks.cs
  • UseProperAssertMethodsAnalyzer.Equality.cs
  • UseProperAssertMethodsAnalyzer.Collection.cs
  • UseProperAssertMethodsAnalyzer.Comparison.cs
  • UseProperAssertMethodsAnalyzer.String.cs

Files to modify:

  • src/Analyzers/MSTest.Analyzers/UseProperAssertMethodsAnalyzer.cs (keep shared declarations)

Task 3: Add a documentation page for the new collection assertion APIs

Priority: Medium
Estimated Effort: Small

Create docs/assert-collection-apis.md summarising the new collection-oriented Assert methods added in v4.x (AreAllDistinct, AreAllNotNull, AreAllOfType, ContainsAll, DoesNotContainAll, AreEquivalent, AreNotEquivalent, IsInRange). Include:

  • Purpose and when to use each method over CollectionAssert equivalents.
  • Code examples.
  • Migration guide from Assert.IsTrue(LINQ expression) patterns.

Link the new page from README.md and docs/Changelog.md.


Task 4: Triage and resolve actionable TODO/FIXME comments

Priority: Low
Estimated Effort: Small

75 TODO/FIXME/HACK comments exist across the codebase. Run a triage pass to:

  1. Convert actionable items into tracked issues.
  2. Remove comments that are no longer relevant.
  3. Add links to existing issues for those already tracked.
grep -rn "TODO\|FIXME\|HACK" --include="*.cs" src/ | grep -v obj/ | grep -v bin/

πŸ“Š Historical Context

Previous Focus Areas
Date Focus Area Type
2026-05-18 New Assert API Analyzer Coverage Custom

🎯 Recommendations

Immediate Actions (This Week)

  1. Extend MSTEST0037 for AreAllNotNull and ContainsAll β€” these have the clearest LINQ analogs and highest user impact. Priority: High.

Short-term Actions (This Month)

  1. Split UseProperAssertMethodsAnalyzer.cs into partial-class files β€” improves long-term maintainability. Priority: Medium.
  2. Add collection API documentation page β€” increases feature discoverability for users upgrading to v4.x. Priority: Medium.
  3. TODO triage β€” 15-minute clean-up pass. Priority: Low.

Generated by Repository Quality Improvement Agent
Next analysis: 2026-05-19 β€” Focus area selected based on diversity algorithm (custom/standard/reuse strategy)

Generated by Repository Quality Improver Β· ● 3.9M Β· β—·

  • expires on May 20, 2026, 10:43 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions