Skip to content

Comments

fix: standardize assertion error message formatting#4933

Merged
thomhurst merged 1 commit intomainfrom
fix/assertion-messages
Feb 19, 2026
Merged

fix: standardize assertion error message formatting#4933
thomhurst merged 1 commit intomainfrom
fix/assertion-messages

Conversation

@thomhurst
Copy link
Owner

Summary

Fixes #4867

  • GetExpectation() now consistently uses the "to [verb] [value]" pattern across all assertion conditions (e.g., "to match regex" instead of "text match regex", "to not match pattern" instead of "text to not match with pattern")
  • Failure messages now consistently use "received [actual]" instead of a mix of "found", "value is", "was", "both values are", etc.
  • Exception type names in throw assertions now consistently use .Name (short name like OtherException) instead of .FullName (fully qualified like TUnit.Assertions.Tests.Assertions.Delegates.Throws+OtherException)

Files changed

17 source files in TUnit.Assertions/Conditions/ and TUnit.Assertions/Collections/:

  • StringAssertions.cs - regex/pattern match expectation wording, failure message standardization
  • StringEqualsAssertion.cs - "found" to "received" in diff messages
  • EqualsAssertion.cs, EquatableAssertion.cs - .FullName to .Name, "found" to "received"
  • NotEqualsAssertion.cs - "both values are" to "received"
  • NullAssertion.cs - "value is null/default" to "received null/default"
  • GreaterThanAssertion.cs, LessThanAssertion.cs, BetweenAssertion.cs - "value is null" / "found" to "received"
  • PredicateAssertions.cs - "value does not satisfy" to "received"
  • ReferenceEqualityAssertions.cs - "references are different/same" to "received different/same references"
  • TypeOfAssertion.cs - "type was" to "received type"
  • AsyncEnumerableAssertions.cs - "was null" / "item X was not found" to "received null" / "X was not found in the collection"
  • CollectionCountSource.cs, CollectionChecks.cs - "found" to "received", "it was empty" to "received empty collection"
  • SetAssertions.cs - "to equal" to "to be equal to" in GetExpectation
  • ThrowsAssertion.cs - .FullName to .Name

10 test files updated to match the new message format.

Test plan

  • dotnet build TUnit.Assertions/TUnit.Assertions.csproj passes with 0 errors
  • dotnet test TUnit.Assertions.Tests/TUnit.Assertions.Tests.csproj - all 6935 tests pass across net8.0, net9.0, net10.0, and net48
  • CI pipeline passes

@claude
Copy link
Contributor

claude bot commented Feb 19, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.


This is a clean, well-executed consistency pass. A few things worth noting positively:

  • Subject-first convention in DoesNotContain: The old found "{expected}" in "{value}" placed the expected value first; the new received "{value}" which contains "{expected}" correctly leads with the actual/received value. This matches the standard assertion reporting convention.
  • .Name over .FullName for exceptions: For nested types like Throws+OtherException, the old .FullName would render as TUnit.Assertions.Tests.Assertions.Delegates.Throws+OtherException — cluttered and hard to read. .Name gives OtherException, which is unambiguous in context and much cleaner in test failure output.
  • GetExpectation() grammar fixes: "text match regex""to match regex" corrects both the grammar and aligns with the "to [verb]" pattern used throughout the library.
  • Test coverage: All 10 test files are properly updated to match the new message format, and the author reports all 6,935 tests passing across net8.0, net9.0, net10.0, and net48.

No CLAUDE.md rule violations, no bugs, no logic issues, no security concerns. The change is purely mechanical string replacements with consistent application across all affected files.

Standardize assertion error messages across TUnit.Assertions for
consistency:

- GetExpectation() now consistently uses "to [verb] [value]" pattern
  (e.g., "to match regex" instead of "text match regex")
- Failure messages now consistently use "received [actual]" pattern
  instead of mixed "found", "value is", "was", "both values are" forms
- Exception type names now consistently use .Name (short name) instead
  of .FullName (fully qualified name)

Changes span 17 source files in TUnit.Assertions/Conditions and
TUnit.Assertions/Collections, with corresponding updates to 10 test
files.
@thomhurst thomhurst force-pushed the fix/assertion-messages branch from f1b432e to b4543a3 Compare February 19, 2026 11:46
@thomhurst thomhurst merged commit ce025a4 into main Feb 19, 2026
13 of 14 checks passed
@thomhurst thomhurst deleted the fix/assertion-messages branch February 19, 2026 13:56
This was referenced Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: inconsistent assertion error message formatting across 86+ files

1 participant