Skip to content
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

MSTEST0037 testing operators == and != #4414

Closed
avivanoff opened this issue Dec 20, 2024 · 5 comments · Fixed by #4456
Closed

MSTEST0037 testing operators == and != #4414

avivanoff opened this issue Dec 20, 2024 · 5 comments · Fixed by #4456

Comments

@avivanoff
Copy link

If you have a class that overloads operators == and !=, writing the proper unit tests results in MSTEST0037: Use proper 'Assert' methods:

public sealed class SomeClass
{
    public static Boolean operator ==(SomeClass left, SomeClass right)
    {
        ...
    }

    public static Boolean operator !=(SomeClass left, SomeClass right)
    {
        ...
    }
}

[TestMethod]
public void SomeClass_TestOperatorEquals()
{
var left = new SomeClass(...);
var right = new SomeClass(...);
Assert.IsTrue(laft == right); // MSTEST0037
}

@Youssef1313
Copy link
Member

Thanks for reporting this.

This was explicitly mentioned in the analyzer docs. But I think the analyzer could be improved.

@avivanoff
Copy link
Author

@Evangelink, @Youssef1313, are the fixes in preview packages? 3.7.1-preview.25052.3 still has the issue.

@Evangelink
Copy link
Member

Evangelink commented Jan 4, 2025

@avivanoff fix wasn't backported yet, I have done it now: #4511.

It should be available on any version from 3.7.1-preview.25054.6

@avivanoff
Copy link
Author

Tested with 3.7.1-preview.25054.10, looks good.

@Youssef1313
Copy link
Member

Thank you for confirming @avivanoff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants