-
-
Notifications
You must be signed in to change notification settings - Fork 0
test: group related assertions with Assert.Multiple #25
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
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.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: dailydevops/frameshift
Length of output: 35883
🌐 Web query:
TUnit Assert.Multiple continue after assertion failed documentation💡 Result:
In TUnit, Assert.Multiple is specifically designed to allow multiple assertions to execute within a test without stopping at the first failure [1]. When assertions are wrapped in a using (Assert.Multiple) block, any failures encountered are accumulated and reported together at the end of the block, rather than throwing an exception immediately upon the first failure [2][1]. Key behaviors and documentation points: - Purpose: It allows you to group related assertions so that all failures are captured and reported, which is useful for diagnosing multiple issues in a single test run [1]. - Implementation: You use it with a using statement. All assertions inside this block that are awaited will be tracked by the scope [1]. - Assertion Execution: It is critical that all assertions within the scope are awaited (using await Assert.That(...)) [3][1]. Unawaited assertions will not execute, and the test may pass incorrectly [1]. - Behavior with Assert.Fail: Historically, there have been nuances regarding whether all methods behave consistently within these blocks. While standard Assert.That calls accumulate correctly [2][1], you should ensure that the assertion methods you use are designed to participate in the TUnit assertion pipeline [2]. If you find that your test is still stopping prematurely, ensure that you are using standard TUnit assertions and that every assertion within the using block is properly awaited [1].
Citations:
Keep dependent diagnostic assertions behind a count gate.
Assert.Multiple()aggregates failures instead of stopping on the first failed assertion. If the diagnostics count assertion fails, the followingdiagnostics[0]assertions still execute and can throw with a less useful exception. Skip index-based assertions when the count is not the expected single value.Proposed pattern
using (Assert.Multiple()) { _ = await Assert.That(diagnostics).Count().IsEqualTo(1); - _ = await Assert.That(diagnostics[0].Location.SourceSpan).IsEqualTo(identifier.Span); - _ = await Assert.That(GetMessage(diagnostics[0]).Contains(name, StringComparison.Ordinal)).IsTrue(); + if (diagnostics.Length == 1) + { + _ = await Assert.That(diagnostics[0].Location.SourceSpan).IsEqualTo(identifier.Span); + _ = await Assert.That(GetMessage(diagnostics[0]).Contains(name, StringComparison.Ordinal)).IsTrue(); + } }📍 Affects 5 files
tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/MSTestSurfaceAnalyzerTests.cs#L182-L189(this comment)tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/MixedFrameworkTestSurfaceTests.cs#L580-L584tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/MixedFrameworkTestSurfaceTests.cs#L715-L719tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/NUnitTestSurfaceAnalyzerTests.cs#L240-L247tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/TUnitTestSurfaceAnalyzerTests.cs#L368-L375tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/TUnitTestSurfaceAnalyzerTests.cs#L427-L437tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/TUnitTestSurfaceAnalyzerTests.cs#L803-L807tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/XunitV2TestSurfaceAnalyzerTests.cs#L225-L232tests/NetEvolve.FrameShift.Tests.Integration/Analyzers/XunitV2TestSurfaceAnalyzerTests.cs#L371-L380🤖 Prompt for AI Agents