These methods test whether the two arguments are equal. Overloaded methods are provided for common value types so that languages that don't automatically box values can use them directly.
Assert.AreEqual( int expected, int actual ); Assert.AreEqual( int expected, int actual, string message ); Assert.AreEqual( int expected, int actual, string message, params object[] parms ); Assert.AreEqual( uint expected, uint actual ); Assert.AreEqual( uint expected, uint actual, string message ); Assert.AreEqual( uint expected, uint actual, string message, params object[] parms ); Assert.AreEqual( decimal expected, decimal actual ); Assert.AreEqual( decimal expected, decimal actual, string message ); Assert.AreEqual( decimal expected, decimal actual, string message, params 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, params 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, params object[] parms ); Assert.AreEqual( object expected, object actual ); Assert.AreEqual( object expected, object actual, string message ); Assert.AreEqual( object expected, object actual, string message, params object[] parms ); Assert.AreNotEqual( int expected, int actual ); Assert.AreNotEqual( int expected, int actual, string message ); Assert.AreNotEqual( int expected, int actual, string message, params object[] parms ); Assert.AreNotEqual( uint expected, uint actual ); Assert.AreNotEqual( uint expected, uint actual, string message ); Assert.AreNotEqual( uint expected, uint actual, string message, params object[] parms ); Assert.AreNotEqual( decimal expected, decimal actual ); Assert.AreNotEqual( decimal expected, decimal actual, string message ); Assert.AreNotEqual( decimal expected, decimal actual, string message, params object[] parms ); Assert.AreNotEqual( float expected, float actual ); Assert.AreNotEqual( float expected, float actual, string message ); Assert.AreNotEqual( float expected, float actual, string message, params object[] parms ); Assert.AreNotEqual( double expected, double actual ); Assert.AreNotEqual( double expected, double actual, string message ); Assert.AreNotEqual( double expected, double actual, string message, params object[] parms ); Assert.AreNotEqual( object expected, object actual ); Assert.AreNotEqual( object expected, object actual, string message ); Assert.AreNotEqual( object expected, object actual, string message, params object[] parms );
The method overloads that compare two objects make special provision so that numeric values of different types compare as expected. This assert succeeds:
Assert.AreEqual( 5, 5.0 );
Values of type float and double are normally compared using an additional argument that indicates a tolerance within which they will be considered as equal. Special values are handled so that the following Asserts succeed:
Assert.AreEqual( double.PositiveInfinity, double.PositiveInfinity ); Assert.AreEqual( double.NegativeInfinity, double.NegativeInfinity ); Assert.AreEqual( double.NaN, double.NaN );
Note: The last example above represents a change with NUnit 2.2.3. In earlier releases, the test would fail. We have made this change because the new behavior seems to be more useful in tests. To avoid confusion, we suggest using the new Assert.IsNaN method where appropriate.
Starting with version 2.2, special provision has been 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.