-2

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

  • 2
    Why you do you want to assert true is equal to true, is this a trick question? Maybe explain your use case in a bit more detail. Did you find this somewhere? – Niels van Reijmersdal Mar 19 '14 at 13:47
  • 2
    Can someone be brave enough to justify downvoting? – dzieciou Mar 19 '14 at 15:03
  • @dzieciou A downvote I believe is automatic when someone issues a vote to close. – corsiKa Mar 19 '14 at 15:16
  • @corsiKa, I have just voted to close and it did not get downvoted. – dzieciou Mar 19 '14 at 15:24
  • 1
    I down voted, there's no detail or context to the question – Phil Kirkham Mar 20 '14 at 11:24
2

You can use Assertions to verify something is in a certain state. Normally you compare the actual against the excepted state.

Example usage:

  • Do some steps in your application
  • Gather the value of a field
  • Assert that the value is indeed the value you expect

    Assert.AreEqual(Actual, Expected)

This could give an assertion failure if Actual and Expected differ. During a test run you should not have any assertion failures. :)

Asserts are often used in unit-tests and automated integration tests to give feedback or actually test something during a test run.

2

Can any one explain Assert.AreEqual(true, true)

Verifies that two specified objects are equal. The assertion fails if the objects are not equal. Displays a message if the assertion fails.

example and explanation?

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 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, I suggest you to read official documentation and answers on stackoverflow:

Not the answer you're looking for? Browse other questions tagged or ask your own question.