断言IEnumerables [英] Assert IEnumerables

查看:105
本文介绍了断言IEnumerables的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于单元测试是不是在我们公司使用的,我自学单元测试自己的代码。
我使用了一些非常基本的单元测试标准的.NET测试框架。

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.

我的一个方法返回一个的IEnumerable<字符串> ,我想测试它的输出。
所以我创建了一个的IEnumerable<串GT; 有望测试它反对。
我以为我记得那里有一种方法 Assert.ArePartsEqual 或类似的东西,但我似乎无法找到它。

A method of mine returns a IEnumerable<string> and I want to test it's output. So I created an IEnumerable<string> expected to test it against. I thought I remembered there to be a way to Assert.ArePartsEqual or something like that, but I can't seem to find it.

因此,在短期,我怎么测试两个的IEnumerable<串> 包含相同的字符串

So in short, how do I test if two IEnumerable<string> contain the same strings?

推荐答案

我不知道是哪个标准的.NET测试框架你指的是,但如果它的Visual Studio Team System的单元测试的东西,你可以使用< A HREF =http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx> CollectionAssert 。

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.

您的考验将是这样的:

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



更新:我忘记CollectionAssert需要一个ICollection接口,所以你会已调用ActualList.ToList()得到它的编译。返回了IEnumerable是一件好事,所以不要改变,只是为测试。

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.

这篇关于断言IEnumerables的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆