You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide an Assert overload to explicitly check self equality #9972
Some of our types override Equality. One of the basic things to check is that an instance is equal to itself.
However, this triggers an MSTEST0032 error.
Perhaps an Assert.SelfEqual(myInstance) could help distinguish between the majority of cases where self-comparison is a typo, and the few cases where it is a deliberate, legitimate test?
I would consider MSTEST0032 a false positive if flagged assertion is going to go through user code, because that means we cannot know if it's always true/false.
Youssef Fahmy (@Youssef1313) Technically I agree. But i found a dozen self-comparisons in our codebase, and only 2 were "intentional". Many of the accidental ones probably went through a custom (user code) equality method. They were still bugs in the test code.
RobSwDev just to be sure, are you saying that if the analyzer wasn't reporting when the type use in Assert.AreEqual/AreNotEqual has cutom equality operator you would have missed broken code/tests?
Activity
Youssef1313 commentedon Jul 15, 2026
I would consider MSTEST0032 a false positive if flagged assertion is going to go through user code, because that means we cannot know if it's always true/false.
RobSwDev commentedon Jul 15, 2026
Youssef Fahmy (@Youssef1313) Technically I agree. But i found a dozen self-comparisons in our codebase, and only 2 were "intentional". Many of the accidental ones probably went through a custom (user code) equality method. They were still bugs in the test code.
Evangelink commentedon Jul 15, 2026
RobSwDev just to be sure, are you saying that if the analyzer wasn't reporting when the type use in Assert.AreEqual/AreNotEqual has cutom equality operator you would have missed broken code/tests?
RobSwDev commentedon Jul 15, 2026
Perhaps not, actually. I was confusing this with the "Collections implementing IEquatable" issue. So Youssef1313 was right.