How does Assert.AreEqual compare two objects in .net unit tests

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I m writing a unit test for some .net code I ve written.

I m familiar with writing code like this:

int expected = 10;
int actual = multiplyByTwo(5);
Assert.AreEqual(expected, actual);

In the case that the arguments are integers, it s clear what to expect the code to do.

What does the code do when the arguments passed in are objects?

If I ve written a custom classed called MyClass, how can I control when Assert.AreEqual passes and failed with objects of type MyClass?

Answers

http://msdn.microsoft.com/en-us/library/ms243413.aspx http://msdn.microsoft.com/en-us/library/ms243413.aspx

That is, two references to the same object would evaluate as being equal; two clones of a same object would evaluate as being different. Unless you overload the Equals() instance method of the class(es) those objects belong to, or the == operator for said class(es).

Also see Reed Copsey s answer.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/17222713/how-does-assert-areequal-compare-two-objects-in-net-unit-tests

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils