Writing UnitTests with MSTest I want to assert the equality of a return value vs. the one I'm expecting.
Expected type is a custom type that does not implement the IComparable
interface nor the IEquatable
interface, thats why I want to give Assert.AreEqual
a possibility to compare the two objects.
I am aware that this possibility exists in CollectionAssert.AreEqual
. This method however requires two ojects that inherit ICollection
which my objects do not.
Why does Assert.AreEqual
not allow me to specify a custom comparer? Am I missing something?
Not sure if this is the actual reason, but what if your custom IComparer
was faulty - your unit test would be meaningless (bearing in mind that the test framework has no way to tell if you wrote unit tests for it let alone if they are "correct")
Could you just create a comparer in your test?
var com = new MyComparer<Foo>();
int expected=0;
int actual = com.Compare(a,b);
if (actual!=0)
{
Assert.Fail("oops");
}
Maybe not ideal, but should work... I also found this question from a few years ago on msdn, with no answers - but an interesting approach to the workaround by the question poster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With