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

Add Assert.AreEquivalent to perform deep comparison of objects #4776

Open
ronaldbosma opened this issue Jan 24, 2025 · 1 comment
Open

Add Assert.AreEquivalent to perform deep comparison of objects #4776

ronaldbosma opened this issue Jan 24, 2025 · 1 comment

Comments

@ronaldbosma
Copy link

ronaldbosma commented Jan 24, 2025

Summary

Add an Assert.AreEquivalent method that performs a deep compare on two objects, similar to for example the xUnit Assert.Equivalent method or FluentAssertion's actual.Should().BeEquivalentTo(expected).

Background and Motivation

I'm trying to perform a deep compare of two objects based on the values of the properties, with the option to exclude certain properties.

I was using FluentAssertions for this, but the latest version got a license change where it's now a paid license for commercial use. The only reason I was using this library is because MSTest doesn't provide a deep comparison option. Instead of having to switch to a different library, it would be useful to have this feature in MSTest itself like xUnit. Reducing the number of dependencies and having better feature parity with xUnit.

Proposed Feature

You can pass two objects into Assert.AreEquivalent(expected, actual) and it will perform a comparison of all (public) fields and properties. It will raise an error if the value of a field/property doesn't match. Using a parameter, you can specify that certain properties should be ignored.

It would also be nice if it could perform a deep compare of the items in two collections. E.g. comparing the first item of each collection using the Assert.AreEquivalent method.

@Evangelink
Copy link
Member

Hi @ronaldbosma,

I think that's an interesting idea but we would need to properly design what we want to support or not. FluentAssertion has tons of options so it will require quite some time to match them all (if we want to). We just looked at xUnit and there are some cases that are strange at first look and that we would need to explore better before we start the implementation.

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

No branches or pull requests

2 participants