Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit Assert.Equals vs. Assert.AreEqual

Tags:

What is the difference between:

  • Assert.Equals and Assert.AreEqual
  • Assert.NotNull and Assert.IsNotNull
  • ...

?

like image 299
chiccodoro Avatar asked Jul 05 '11 13:07

chiccodoro


People also ask

What is the difference between assert AreEqual and assert AreSame?

It means that AreSame() checks that they are the exact same object - if reference indicate the same object in memory. AreEqual() checks that objects has equal type and value. Equal objects can exist in two different places in memory.

What is assert AreEqual?

Tests whether the specified objects are equal and throws an exception if the two objects are not equal. Different numeric types are treated as unequal even if the logical values are equal.

How do you compare two objects in assert?

Assert. AreEqual() compares references. Usually when comparing lists I compare the count of the items and than some properties of one exact item in the list or directly the item in the list (but again it is the reference).

How do you assert equal in C#?

Assert. Equal(expected.Name, actual.Name); The first example fails due to the way comparison works for reference types. By default, the equality operation for those types will only assert whether the two objects being compared are the same, namely your variables are pointing to the same object within the memory heap.


2 Answers

Assert.Equals is an object comparison

Assert.AreEquals is overloaded to compare (int,double, object) etc

Assert.NotNull and Assert.IsNotNul appear to be identical.

http://www.nunit.org/index.php?p=conditionAsserts&r=2.5.5

like image 75
ChrisBint Avatar answered Nov 30 '22 23:11

ChrisBint


Just read the documentation:

NUnit - ConditionAsserts

Two forms are provided for the True, False, Null and NotNull conditions. The "Is" forms are compatible with earlier versions of the NUnit framework, while those without "Is" are provided for compatibility with NUnitLite.

like image 45
Justin Niessner Avatar answered Dec 01 '22 01:12

Justin Niessner