Assert IEnumerables

前端 未结 4 1508
死守一世寂寞
死守一世寂寞 2021-02-18 19:10

As unit testing is not used in our firm, I\'m teaching myself to unit test my own code. I\'m using the standard .net test framework for some really basic unit testing.

A

4条回答
  •  情话喂你
    2021-02-18 20:00

    I don't know which "standard .net test framework" you're referring to, but if it's Visual Studio Team System Unit testing stuff you could use CollectionAssert.

    Your test would be like this:

    CollectionAssert.AreEqual(ExpectedList, ActualList, "...");
    

    Update: I forgot CollectionAssert needs an ICollection interface, so you'll have to call ActualList.ToList() to get it to compile. Returning the IEnumerable is a good thing, so don't change that just for the tests.

提交回复
热议问题