You must Sign In to post a response.
  • Category: .NET

    NUnit - please, how is this Assert statement true

    Assert.AreSame(int.Parse("1"),int.Parse("1"),
    "this test should fail").

    How on should this assert statement fail?
    I figured they are thesame, so should pass. Right?
  • #768680
    Hi,

    We can use many statements for finding out the Boolean values.
    Infact the following list of statements can be used to find the Boolean values of a particular statement.


    Assert.IsTrue( bool condition );
    Assert.IsTrue( bool condition, string message );
    Assert.IsTrue( bool condition, string message, object[] parms );
    Assert.True( bool condition );
    Assert.True( bool condition, string message );
    Assert.True( bool condition, string message, object[] parms );



    All this statement will work on the Boolean values especially for true return.
    Mostly this will be used in TextBox kind of testing like ,
    1. Is the textbox is filled with characters
    2. Is the textbox is filled only with numeric
    3. Is the textbox is empty

    Thanks,
    Mani

  • #768687
    HI Michael,
    Yes, you are right, both are same so it will pass. If both are not same, then the second parameter i.e. message will be shown: "this test should fail".

    Thanks

    Reena

  • #768700
    Assert class is used to Verifies conditions in unit tests using true/false propositions,
    you have used AreSame method, Verifies that two specified object variables refer to the same object

    I think you should use 'AreEqual' method it Verifies that two specified objects are equal. The assertion fails if the objects are not equal. Displays a message if the assertion fails.
    Different numeric types are treated as equal if the logical values are equal. For example, 42L is equal to 42

    Hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


  • Sign In to post your comments