Unit-testing IList with CollectionAssert

守給你的承諾、 提交于 2019-12-01 13:58:32

问题


The MSTest framework has a CollectionAssert that accepts ICollections. My method returns an IList. Apparently a list is not a collection..

Are there ways to make my IList an ICollection?


回答1:


You could call the ToArray() extension method on it - Array implements ICollection

Edit: Also, while List<T> implements ICollection, IList<T> only implements ICollection<T> which does not implement ICollection, so if you know the item in the test is a List<T>, you should be able to cast it...




回答2:


You can send in a List

    List<string> actual = new List<string>(){"1","2","3"};
    List<string> expected = new List<string>(){"1","2","**EditCaseFalse**"};
    CollectionAssert.AreEqual(actual,expected)

I get back Failed (third element does not match.)



来源:https://stackoverflow.com/questions/662458/unit-testing-ilist-with-collectionassert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!