NUnit comparing two lists

后端 未结 6 509
孤独总比滥情好
孤独总比滥情好 2021-01-01 10:16

OK so I\'m fairly new to unit testing and everything is going well until now. I\'m simplifying my problem here, but basically I have the following:

[Test]
pu         


        
6条回答
  •  死守一世寂寞
    2021-01-01 11:17

    From Nunit documentation:

    Starting with version 2.2, special provision is also 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.

    You have a list of objects ... so it's not the same as comparing 2 ints. What you should do is probably compare all the objects inside the list ... (Try converting your list to an array ... might actually work :) )


    As I said (and most others as well), you'll probably need to override Equals. Here's MSDN page about how to do it (Covers Equals, == operator, and GetHashCode).

    Similar with more info : [compare-equality-between-two-objects-in-nunit]
    (Compare equality between two objects in NUnit)

提交回复
热议问题