Add [StackTraceHidden] to assertion API internals#8853
Merged
Evangelink merged 3 commits intoJun 5, 2026
Merged
Conversation
Addresses feedback from @Youssef1313 on microsoft#8826: use [StackTraceHidden] instead of manually filtering stack frames. Applies the attribute to nested helper types inside the assertion API that previously could leak into user-facing failure stack traces: - NonGenericEqualityComparerAdapter (Assert.AreAllDistinct) - TypeMismatch (Assert.AreAllOfType) - EquivalenceComparer partial (Assert.AreEquivalent.Comparer) - DictionaryView, DictionaryLookup, NonGenericDictionaryView, GenericDictionaryView, GenericDictionaryAccessors (Assert.AreEquivalent.DictionaryView) - ReferenceObjectComparer, MemberLookup, MemberAccessor (Assert.AreEquivalent.MemberAccessor) - EquivalenceMismatch (Assert.AreEquivalent.Mismatch) - ThrowsExceptionState (Assert.ThrowsException) - ObjectComparer (CollectionAssert.Helpers) Enum-typed helpers (IEquatableOutcome, ThrowsFailureKind) are skipped because [StackTraceHidden] does not target enums. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends [StackTraceHidden] coverage within the MSTest assertion implementation (src/TestFramework/TestFramework/Assertions/*) by annotating additional nested/internal helper types that can otherwise appear in user-facing failure stack traces.
Changes:
- Add
[StackTraceHidden]to additional nested assertion helper types inAssert.AreEquivalent.*(comparer, mismatch, member accessor, dictionary view). - Add
[StackTraceHidden]to helper types used byAssert.AreAllDistinct,Assert.AreAllOfType, andAssert.ThrowsException. - Add
[StackTraceHidden]toCollectionAssert’s internalObjectComparer.
Show a summary per file
| File | Description |
|---|---|
| src/TestFramework/TestFramework/Assertions/CollectionAssert.Helpers.cs | Hides ObjectComparer helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs | Hides ThrowsExceptionState helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreEquivalent.Mismatch.cs | Hides EquivalenceMismatch helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreEquivalent.MemberAccessor.cs | Hides member-access and reference-compare helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreEquivalent.DictionaryView.cs | Hides dictionary abstraction/lookup/accessor helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreEquivalent.Comparer.cs | Hides EquivalenceComparer internal comparer frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreAllOfType.cs | Hides TypeMismatch helper frames from stack traces. |
| src/TestFramework/TestFramework/Assertions/Assert.AreAllDistinct.cs | Hides comparer adapter frames from stack traces. |
Copilot's findings
- Files reviewed: 8/8 changed files
- Comments generated: 2
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
azat-msft
approved these changes
Jun 5, 2026
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.
Addresses feedback from @Youssef1313 on #8826 (#8826 (comment)):
This PR adds
[StackTraceHidden]to nested helper types inside the assertion API that previously could leak into user-facing failure stack traces:NonGenericEqualityComparerAdapter(Assert.AreAllDistinct)TypeMismatch(Assert.AreAllOfType)EquivalenceComparerpartial (Assert.AreEquivalent.Comparerand sibling partials)DictionaryView,DictionaryLookup,NonGenericDictionaryView,GenericDictionaryView,GenericDictionaryAccessors(Assert.AreEquivalent.DictionaryView)ReferenceObjectComparer,MemberLookup,MemberAccessor(Assert.AreEquivalent.MemberAccessor)EquivalenceMismatch(Assert.AreEquivalent.Mismatch)ThrowsExceptionState(Assert.ThrowsException)ObjectComparer(CollectionAssert.Helpers)Top-level assertion types (
Assert,CollectionAssert,StringAssert,AssertExtensions,AssertScope, etc.) and allInterpolatedStringHandlerstructs were already annotated, so this PR fills in the remaining nested helpers withinsrc/TestFramework/TestFramework/Assertions/.Enum-typed helpers (
IEquatableOutcome,ThrowsFailureKind) are skipped because[StackTraceHidden]does not target enums.Notes / out of scope
[StackTraceHidden]and not addressed here.