Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 1, 2025

Summary

This PR adds comprehensive documentation for five new MSTest analyzer rules (MSTEST0051 through MSTEST0055) that were introduced in MSTest 3.10.0.

Changes

New Documentation Files

Created documentation for the following analyzers:

  1. MSTEST0051: Assert.Throws should contain a single statement

    • Ensures that Assert.Throws, Assert.ThrowsAsync, Assert.ThrowsExactly, and Assert.ThrowsExactlyAsync methods contain exactly one statement in the action delegate to avoid ambiguous test results
    • Severity: Info
  2. MSTEST0052: Prefer DynamicDataSourceType.AutoDetect

    • Recommends using the default DynamicDataSourceType.AutoDetect (introduced in MSTest 3.8) instead of explicitly specifying Property or Method for better maintainability
    • Severity: Warning
    • Has code fix
  3. MSTEST0053: Avoid Assert method format parameters

    • Encourages using string interpolation instead of the legacy message format parameters in assertion methods for better compile-time safety and readability
    • Severity: Warning
    • Has code fix
  4. MSTEST0054: Use cancellation token from TestContext.CancellationToken

    • Promotes using the TestContext.CancellationToken property instead of creating separate cancellation tokens to ensure proper integration with test timeouts and cooperative cancellation
    • Severity: Info
  5. MSTEST0055: String method return value should not be ignored

    • Detects when string manipulation methods like ToUpper(), ToLower(), Trim(), Replace(), or Substring() are called without using their return values, which is always a bug due to string immutability
    • Severity: Warning

Updated Files

  • usage-rules.md: Added entries for all five new analyzers in the usage rules table
  • Updated ms.date to reflect the latest changes
  • docs/navigate/devops-testing/toc.yml: Added TOC entries for all five new analyzers in the Usage section

Documentation Standards

All documentation files follow the established patterns:

  • Consistent YAML frontmatter with proper metadata and ai-usage: ai-generated disclosure
  • Standard structure: Cause, Rule description, How to fix violations, When to suppress warnings
  • Proper xref links to MSTest and .NET API documentation
  • Clear before/after code examples in C#
  • Compliance with Microsoft Writing Style Guide

References

The implementations for these analyzers were added in the following PRs:

Original prompt

This section details on the original issue you should resolve

<issue_title>Document MSTEST0051-MSTEST0055</issue_title>
<issue_description>### Describe the issue or suggestion

Rule ID Category Severity Notes
MSTEST0051 Usage Info AssertThrowsShouldContainSingleStatementAnalyzer, Documentation
MSTEST0052 Usage Warning PreferDynamicDataSourceTypeAutoDetectAnalyzer, Documentation
MSTEST0053 Usage Warning AvoidAssertFormatParametersAnalyzer, Documentation
MSTEST0054 Usage Info UseCancellationTokenPropertyAnalyzer, Documentation
MSTEST0055 Usage Warning IgnoreStringMethodReturnValueAnalyzer, Documentation

These need to be documented.</issue_description>

Comments on the Issue (you are @copilot in this section)

@Youssef1313 PRs that implemented these analyzers:

microsoft/testfx#6190
microsoft/testfx#6261
microsoft/testfx#6294
microsoft/testfx#6429
microsoft/testfx#6482</comment_new>

Fixes #48811

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/core/testing/mstest-analyzers/mstest0051.md MSTEST0051: Assert.Throws should contain only a single statement
docs/core/testing/mstest-analyzers/mstest0052.md "MSTEST0052: Avoid passing an explicit 'DynamicDataSourceType' and use the default auto detect behavior"
docs/core/testing/mstest-analyzers/mstest0053.md MSTEST0053: Avoid using Assert methods with format parameters
docs/core/testing/mstest-analyzers/mstest0054.md MSTEST0054: Use cancellation token from TestContext.CancellationToken
docs/core/testing/mstest-analyzers/mstest0055.md docs/core/testing/mstest-analyzers/mstest0055
docs/core/testing/mstest-analyzers/usage-rules.md MSTest usage rules
docs/navigate/devops-testing/toc.yml docs/navigate/devops-testing/toc

@dotnet-policy-service dotnet-policy-service bot added the okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings. label Oct 1, 2025
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
@Youssef1313
Copy link
Member

@copilot Please update docs/navigate/devops-testing/toc.yml

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Document MSTEST0051-MSTEST0055 Document MSTest analyzers MSTEST0051-MSTEST0055 Oct 1, 2025
@Copilot Copilot AI requested a review from Youssef1313 October 1, 2025 12:08
Copilot finished work on behalf of Youssef1313 October 1, 2025 12:08
Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 1, 2025

@copilot Please update docs/navigate/devops-testing/toc.yml

Updated in commit e883950. Added TOC entries for MSTEST0051, MSTEST0052, MSTEST0053, MSTEST0054, and MSTEST0055 to the Usage section.

Copilot finished work on behalf of Youssef1313 October 1, 2025 12:12
@Youssef1313 Youssef1313 marked this pull request as ready for review October 1, 2025 12:47
@Youssef1313 Youssef1313 requested review from IEvangelist and a team as code owners October 1, 2025 12:47
@meaghanlewis meaghanlewis merged commit fd4d88a into main Oct 3, 2025
10 checks passed
@meaghanlewis meaghanlewis deleted the copilot/fix-e7bb6a55-27a8-49f8-b994-80ff28689b26 branch October 3, 2025 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fundamentals/svc okr-quality Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document MSTEST0051-MSTEST0055
3 participants