Using Assert to compare two objects

Posted by baron on Stack Overflow See other posts from Stack Overflow or by baron
Published on 2010-05-06T03:51:41Z Indexed on 2010/05/06 3:58 UTC
Read the original article Hit count: 225

Filed under:
|
|
|
|

Hi everyone,

Writing test cases for my project, one test I need is to test deletion. This may not exactly be the right way to go about it, but I've stumbled upon something which isn't making sense to me.

Code is like this:

[Test]
private void DeleteFruit()
{
    BuildTestData();
    var f1 = new Fruit("Banana",1,1.5);
    var f2 = new Fruit("Apple",1,1.5);
    fm.DeleteFruit(f1,listOfFruit);
    Assert.That(listOfFruit[1] == f2);
}

Now the fruit object I create line 5 is the object that I know should be in that position (with this specific dataset) after f1 is deleted.

Also if I sit and debug, and manually compare objects listOfFruit[1] and f2 they are the same. But that Assert line fails. What gives?

© Stack Overflow or respective owner

Related posts about nunit

Related posts about test