Skip to content

Document Assert.That custom assertions and de-emphasize StringAssert/CollectionAssert#54185

Open
Evangelink wants to merge 3 commits into
mainfrom
dev/amauryleve/mstest-assert-that-custom-assertions
Open

Document Assert.That custom assertions and de-emphasize StringAssert/CollectionAssert#54185
Evangelink wants to merge 3 commits into
mainfrom
dev/amauryleve/mstest-assert-that-custom-assertions

Conversation

@Evangelink

@Evangelink Evangelink commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

Updates the MSTest assertions article to:

  1. Document the Assert.That, StringAssert.That, and CollectionAssert.That extensibility hook (the singleton property used as a target for user-authored extension methods, per testfx RFC 002).
  2. Strengthen the guidance that StringAssert and CollectionAssert are not recommended for new code and are likely to be deprecated. The main reason is discoverability: splitting assertions across three types means you can't see all available checks in a single IntelliSense list.

Contributes to microsoft/testfx#8818

Changes

  • New section Create custom assertions with Assert.That with:
    • A C# extension method example (IsPrime) that targets the Assert instance type.
    • A call-site example showing Assert.That.IsPrime(result).
    • A subsection acknowledging StringAssert.That and CollectionAssert.That exist for the same pattern, but recommending Assert.That for new code.
    • A disambiguation NOTE clarifying the singleton property (Assert.That.MyAssertion(...)) is distinct from the MSTest 3.8 expression-tree method (Assert.That(() => condition)).
  • Strengthened deprecation messaging on StringAssert and CollectionAssert (NOTE → WARNING), and updated the top-of-doc callout from TIP → IMPORTANT explaining the discoverability problem.
  • New best-practice bullet recommending custom assertions extend Assert.That (not StringAssert.That/CollectionAssert.That).
  • Added ai-usage: ai-assisted and bumped ms.date.

Verification

  • npx markdownlint-cli2 passes with 0 errors.
  • All three new <xref:...> API IDs (Assert.That, StringAssert.That, CollectionAssert.That) resolve against the Microsoft Learn API browser.

Content source


Internal previews

📄 File 🔗 Preview link
docs/core/testing/unit-testing-mstest-writing-tests-assertions.md MSTest assertions

…lectionAssert guidance

- Add 'Create custom assertions with Assert.That' section explaining the singleton extensibility hook with a worked extension method example.
- Note that StringAssert.That and CollectionAssert.That exist for the same pattern but recommend Assert.That for new code.
- Disambiguate the singleton property from the MSTest 3.8 Assert.That(() => condition) expression-tree method.
- Strengthen messaging that StringAssert and CollectionAssert are likely to be deprecated and aren't recommended due to discoverability issues.
- Add ai-usage: ai-assisted and bump ms.date.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 13:04
@dotnetrepoman dotnetrepoman Bot added this to the June 2026 milestone Jun 4, 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

Updates the MSTest assertions documentation to explain the *.That extensibility hook for custom assertions and to steer new code away from StringAssert/CollectionAssert due to discoverability and likely future deprecation.

Changes:

  • Replaces the top callout with stronger guidance to prefer Assert and warns about likely deprecation of StringAssert/CollectionAssert.
  • Adds a new section documenting custom assertions via Assert.That (and mentions StringAssert.That/CollectionAssert.That).
  • Updates best-practices guidance to recommend extending Assert.That, and adds ai-usage plus an updated ms.date.
Show a summary per file
File Description
docs/core/testing/unit-testing-mstest-writing-tests-assertions.md Adds Assert.That extensibility documentation and strengthens guidance away from StringAssert/CollectionAssert.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md
Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md Outdated
Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md
…e disambiguation NOTE

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
Member Author

@meaghanlewis @gewarren could you please review?

Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md Outdated
Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md Outdated
Comment thread docs/core/testing/unit-testing-mstest-writing-tests-assertions.md Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink closed this Jun 9, 2026
auto-merge was automatically disabled June 9, 2026 08:08

Pull request was closed

@Evangelink Evangelink reopened this Jun 9, 2026
@Evangelink Evangelink enabled auto-merge (squash) June 9, 2026 08:09
@Evangelink

Copy link
Copy Markdown
Member Author

@gewarren I am not sure how to fix the error on this PR, could you please help?

@gewarren

gewarren commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@gewarren I am not sure how to fix the error on this PR, could you please help?

They've disabled OPS builds since the weekend. They hope to turn them back on today :-S.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants