Comparisons

Assertions that perform comparisons are often your best choice because they report both expected and actual values. The expected value is always the first argument. NUnit provides the following comparison asserts:

Assert.AreEqual( int expected, int actual );
Assert.AreEqual( int expected, int actual, string message );
Assert.AreEqual( int expected, int actual, string message, 
                 object[] parms );

Assert.AreEqual( decimal expected, decimal actual );
Assert.AreEqual( decimal expected, decimal actual, string message );
Assert.AreEqual( decimal expected, decimal actual, string message, 
                 object[] parms );

Assert.AreEqual( float expected, float actual, float tolerance );
Assert.AreEqual( float expected, float actual, float tolerance,
                 string message );
Assert.AreEqual( float expected, float actual, float tolerance,
                 string message, object[] parms );

Assert.AreEqual( double expected, double actual, double tolerance );
Assert.AreEqual( double expected, double actual, double tolerance,
                 string message );
Assert.AreEqual( double expected, double actual, double tolerance,
                 string message, object[] parms );

Assert.AreEqual( object expected, object actual );
Assert.AreEqual( object expected, object actual, string message );
Assert.AreEqual( object expected, object actual, string message, 
                 object[] parms );

Assert.AreSame( object expected, object actual );
Assert.AreSame( object expected, object actual, string message );
Assert.AreSame( object expected, object actual, string message, 
                object[] parms );

The AreSame method tests that the same objects are referenced by both arguments. All the variants of AreEqual test for equality.

Overloaded AreEqual methods are provided for the most common types. In addition, the overload that compares two objects makes special provisions so that numeric values of different types compare as expected. This makes it possible for asserts like the following to succeed:

        Assert.AreEqual( 5, 5.0 )

Starting with version 2.2, special provision is also made for comparing single-dimensioned arrays. Two arrays will be treated as equal by Assert.AreEqual if they are the same length and each of the corresponding elements is equal. Note: Multi-dimensioned arrays, nested arrays (arrays of arrays) and other collection types such as ArrayList are not currently supported.