-
-
Notifications
You must be signed in to change notification settings - Fork 109
feat: enhance assertion exception messages to include inline 'because' reasons #4142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Code ReviewThank you for this PR! The implementation looks solid and addresses issue #4085 well. Strengths
Observations
Potential Considerations
Recommendations
Pre-Commit ChecklistAll items from CLAUDE.md checklist satisfied: tests added, modern C# style, no breaking changes, minimal focused change, no performance concerns, no dual-mode needed, no snapshot updates needed. Final VerdictLGTM with minor suggestion The implementation is clean, well-tested, and solves the user problem effectively. The only enhancement would be validation for empty/whitespace because messages, but that is a minor quality improvement, not a blocker. Great work on improving the developer experience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances assertion exception messages by moving the "because" reason inline with the expectation statement, rather than appending it as a separate line. This change improves readability by keeping the reason directly adjacent to what's being asserted.
Key Changes:
- Modified the exception message format to append the "because" reason inline with the expectation (using a comma separator)
- Added a comprehensive test to verify the new inline format works correctly
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| TUnit.Assertions/Core/Assertion.cs | Refactored CreateException method to build the expectation with inline "because" message before constructing the full error message |
| TUnit.Assertions.Tests/AssertConditions/BecauseTests.cs | Added new test Because_Message_Appears_Inline_With_Expectation to verify the new format produces the expected inline message structure |
The changes look good overall! The implementation is clean and consistent with the existing patterns in AndAssertion and OrAssertion classes which already format "because" messages inline. The test coverage is adequate, and the code follows proper style guidelines.
Fixes #4085