Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get NUnit to be more specific about which fields don't match when comparing objects?

Tags:

c#

nunit

I have 2 objects (one hand crafted that is my expected and one is coming from the database) and I'm trying to ensure they are equal. Not as in that they are the same reference but that the data within them matches.

I'm using Assert.AreEqual() but only get generic error messages such as.

Expected: <Namespace.ObjectFoo>
But was: <Namespace.ObjectFoo>

How can I drill to further to display which properties don't match?

like image 845
Nosila Avatar asked Jan 17 '23 21:01

Nosila


1 Answers

Add a .ToString() override on the Namespace.ObjectFoo class that describes the object's contents. The <Namespace.ObjectFoo> is the output from the implementation of .ToString() defined on System.Object.

like image 164
Chris Shain Avatar answered Feb 08 '23 13:02

Chris Shain