对于 Visual Studio 2008 中的 C#,我应该从哪个单元测试框架开始? (Windows 窗体应用程序)
问题 - 如果我使用 Visual Studio 2008 在 C# 中启动 Windows 窗体应用程序,我应该使用哪个单元测试框架?
VS2008 似乎有一个内置版本?或者我应该研究像 NUnit 这样的东西?或者NUnit是在VS2008中使用的?什么是最受欢迎的。
如果有一些东西可以实现: (a) 模拟/存根,以及 (b) 断言异常的能力,
谢谢
QUESTION - If I'm starting a Windows Forms application in C# using Visual Studio 2008, which unit testing framework should I use?
There seems to be one build into VS2008? Or should I look into something like NUnit? Or is NUnit what is used in VS2008 under the bonnet? What's the most popular.
Would be good to have something that allows for:
(a) mocking/stubs, and
(b) ability to assert exceptions
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我建议您使用 NUnit 作为测试框架。如果您需要在构建服务器上设置它,它非常轻量级并且易于运输。使用 MSTest 时情况并非如此。至于模拟/隔离框架,Rhino Mocks 拥有最大的用户群,您可能会通过 Rhino Mocks 最快地找到问题的答案。
I would recommend using NUnit for your testing framework. It's very lightweight and easy to ship around if you need to get it set up on a build server. This isn't the case using MSTest. As for mocking/isolation frameworks, Rhino Mocks has the largest user base and you're likely to find answers to your questions quickest with Rhino Mocks.
如果只是一个简单的应用程序,VS2008 中内置的 MSTest 框架应该满足所有条件。它与 NUnit 不同,尽管很多人(错误地)将其视为同一事物。
我从未用它来嘲笑,所以也许其他人可以详细说明这一点。它会在您的解决方案中生成一个单独的项目,仅用于测试目的。 这是关于如何使用它的很好的解释。
< br>
(来源:geekzone.co.nz)
编辑:
做了更多的挖掘,我发现 MSTest 和 NUnit 的比较。
NUnit 框架的缺点:
这是来自我链接到的比较文章。
我从未使用过 NUnit,只使用过 C# 的 MSTest 和 Java 的 JUnit,所以我在这方面有点偏见。 MSTest 对于我来说对于 WinForms 一直非常有效,其功能包括能够单独运行测试、显示非常详细的报告(带有单独的跟踪日志)以及自动生成所有样板测试代码并执行所有这些操作这些因素使得 VS2008 成为如此出色的 IDE。听起来,NUnit 对于其他人来说效果很好,他们也有喜欢它的理由。
除非你有特殊的理由采用 NUnit/Testdriven.NET 方法,比如你需要某个功能,或者你只是更喜欢这种设置测试并尝试将其集成回 VS 的方式,那么我看不出有任何理由不仅仅是使用开箱即用的 MSTest。
If it just a simple application, the MSTest framework built into VS2008 should tick all the boxes. It is not the same as NUnit, though a lot of people (mistakenly) refer to it as if they were the same thing.
I have never used it for mocking, so maybe someone else can elaborate on that. It generates a separate project in your solution that is just for the purpose of testing. This is a good explanation of how to use it.
(source: geekzone.co.nz)
Edit:
Doing a bit more digging, I came across this comparison of MSTest and NUnit.
Drawbacks of NUnit Framework:
That's from the comparison article I linked to.
I have never used NUnit, only MSTest for C# and JUnit for Java, so I am kind of biased in that respect. MSTest has always worked really well for me for WinForms, with features like being able to run the tests individually, show really detailed reports (with individual trace logs) and autogenerate all the boilerplate test code and do all those kind of things that make VS2008 such a brilliant IDE. By the sounds of it, NUnit has worked well for others and they have their reasons why they like it.
Unless you have a particular reason to take the NUnit/Testdriven.NET approach, like you need a certain feature, or you just prefer that way of setting up tests and trying to integrate it back into VS, then I don't see any reason not to just use MSTest which works right out of the box.
我们从 MSTest 开始。它具有在 NUnit 中(稍微)难以复制的优点。它允许您访问类的私有成员。当您检查状态时,这是非常宝贵的。例如,假设我有一个函数,可以将条目放入未公开的字典中。我的理解是,使用 NUnit 你必须使用反射来访问字典,或者添加一个 getter 来进行测试。在这里,你可以查一下字典。非常简单而且非常干净。它还允许您测试我喜欢的私有函数(我知道有些人不相信这一点)。虽然我不喜欢 MSTest,但该功能使测试变得更加容易。
VS 集成也很好。
We've started with MSTest. It has an advantage that is (mildly) difficult to replicate in NUnit. It allows you to access private members of the class. This is invaluable when you are checking state. For instance, say that I have a function that puts entries into a dictionary that is not exposed. My understanding, is that with NUnit you have to use reflection to get to the dictionary, or add a getter for the sole purpose of testing. Here, you can just check the dictionary. Very easy and very clean. It also allows you to test private functions, which I love (I know some people don't believe in this). While I don't love MSTest, that feature makes testing much easier.
VS integration is also nice.
使用 MSTest。它内置于 VS2008 中,并在 IDE 中支持创建测试函数。如果您“不再需要”MSTest,那么您应该考虑 NUnit 或更现代的 xUnit。您可以通过使用 ExpectedException 属性进行修饰来预期 MSTest 中出现异常。
模拟框架独立于您选择的测试框架。模拟框架的热门选择是:Moq 和 Rhino 模拟。
Use MSTest. It's built into VS2008 and has support in the IDE for creating test functions. If and when you "outgrow" MSTest, then you should look at NUnit or the more modern xUnit. You can expect exceptions in MSTest by decorating with the ExpectedException attribute.
Mocking frameworks are independent of your choice of testing framework. Popular choices for mocking framework are: Moq and Rhino Mocks.
我想说,为了简单起见,从 Visual Studio 2008 中内置的那个开始。NUnit 非常棒,我经常使用它,所以一旦您熟悉了编写单元测试,您就可以继续使用 NUnit。
i would say, for simplicity, start with the one built into visual studio 2008. NUnit is fantastic and i use it alot, so you can probably move on to NUnit once your comfortable with writing unit tests.
您没有提到您是否要测试驱动代码。
我建议买一本薄书 '实用使用 NUnit' 在 C# 中进行单元测试,并至少进行一次。
在 NUnit v MSTest 线上,我不适合发表评论。 MSTest 的飞行时间为 0。
You didn't mention if you were going to be test-driving code..
I'd recommend getting a thin book 'Pragmatic Unit Testing in C# with NUnit' and going through it atleast once.
On the NUnit v MSTest line, I'm not fit to comment. 0 flying-time with MSTest.