What does assert.areequal do?

444    Asked by Amitraj in Cyber Security , Asked on Apr 21, 2022

Can any one explain Assert.AreEqual(true, true); with proper example and explanation?

Answered by Amit Sinha

Very simple NUnit test: using System; 

using NUnit.Framework; namespace SampleUnitTest{
  [TestFixture]
  public Class SampleTest
  {
    [Test]
    public void AddingOneAndOneResultsInTwo()
    {
      int two = 1 + 1;
      Assert.AreEqual(2, two);
    }
  }
}

Explanation is simple too, integer value two equals 2 and then method Assert.AreEqual(2, two) compares two values 2 and two. That is, two references to the same object would evaluate as being equal; two clones of the 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, I suggest you to read official documentation and answers on stackoverflow: http://msdn.microsoft.com/en-us/library/ms243413.aspx https://stackoverflow.com/questions/17222713/how-does-assert-areequal-compare-two-objects-in-net-unit-tests



Your Answer

Interviews

Parent Categories