Document Assert.That custom assertions and de-emphasize StringAssert/CollectionAssert#54185
Open
Evangelink wants to merge 3 commits into
Open
Document Assert.That custom assertions and de-emphasize StringAssert/CollectionAssert#54185Evangelink wants to merge 3 commits into
Evangelink wants to merge 3 commits into
Conversation
…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>
Contributor
There was a problem hiding this comment.
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
Assertand warns about likely deprecation ofStringAssert/CollectionAssert. - Adds a new section documenting custom assertions via
Assert.That(and mentionsStringAssert.That/CollectionAssert.That). - Updates best-practices guidance to recommend extending
Assert.That, and addsai-usageplus an updatedms.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
Evangelink
commented
Jun 4, 2026
…e disambiguation NOTE Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
@meaghanlewis @gewarren could you please review? |
gewarren
approved these changes
Jun 5, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
@gewarren I am not sure how to fix the error on this PR, could you please help? |
Contributor
They've disabled OPS builds since the weekend. They hope to turn them back on today :-S. |
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.
Summary
Updates the MSTest assertions article to:
Assert.That,StringAssert.That, andCollectionAssert.Thatextensibility hook (the singleton property used as a target for user-authored extension methods, per testfx RFC 002).StringAssertandCollectionAssertare 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
Create custom assertions with Assert.Thatwith:IsPrime) that targets theAssertinstance type.Assert.That.IsPrime(result).StringAssert.ThatandCollectionAssert.Thatexist for the same pattern, but recommendingAssert.Thatfor new code.Assert.That.MyAssertion(...)) is distinct from the MSTest 3.8 expression-tree method (Assert.That(() => condition)).StringAssertandCollectionAssert(NOTE → WARNING), and updated the top-of-doc callout from TIP → IMPORTANT explaining the discoverability problem.Assert.That(notStringAssert.That/CollectionAssert.That).ai-usage: ai-assistedand bumpedms.date.Verification
npx markdownlint-cli2passes with 0 errors.<xref:...>API IDs (Assert.That,StringAssert.That,CollectionAssert.That) resolve against the Microsoft Learn API browser.Content source
Assert.cs,StringAssert.cs,CollectionAssert.cs,Assert.That.cs) and RFC 002 — Framework Extensibility for Custom Assertions.[Obsolete]attribute is shipped yet.Internal previews