我希望在我的工作中引入单元测试框架。我们正在使用 Visual Studio 2005(尽管我们可能会在接下来的六个月内迁移到 2008)并且主要使用 C# 进行工作。如果该框架具有某种 IDE 集成,那将是最好的,但我对没有集成但设置起来仍然相对简单的框架持开放态度。我会以某种方式抵制它,所以如果我能确定我推的东西不会让脖子疼痛,那将有助于我的案子。 到目前为止,根据我所做的研究,显而易见的选择指向 NUnit,但我想在向我的团队推荐它之前获得实际使用它的人的印象。 有人在那里使用过NUnit吗?如果是这样,是否有任何我应该注意的陷阱或限制?还有其他好的选择吗?如果是这样,如果您同时使用过 NUnit,我将非常感谢您了解它们的优点和缺点。


我认为NUnit 是您最好的选择。借助TestDriven.NET,您可以在 Visual Studio 中实现出色的集成。(ReSharper 也有一个单元测试运行器,如果您正在使用的话)。NUnit 易于使用并遵循既定的范例。您还会发现大量使用它的项目、教程和指南,它们总是有帮助的。 您的另一个主要选择可能是MbUnit,它越来越多地将自己定位为首选的BDD框架(与Gallio结合使用)。
斯科特·汉塞尔曼 (Scott Hanselman)对此有一个很好的播客,标题为: “.NET 单元测试框架的过去、现在和未来” : Hanselminutes #112
Visual Studio 2008 has a built-in test project type that works in a similar way to NUnit, but obviously has much tighter integration with Visual Studio (can run on every build and shows the results in a similar way to the conversion results page when upgrading solution files), but it is obviously not as mature as NUnit as it's pretty new and I'm not sure about how it handles mocking. But it would be worth looking into when your team moves to Visual Studio 2008.
The built-in unit testing in Visual Studio 2008 is all right, but its difficult to integrate with CruiseControl.NET, certainly a lot harder than normal NUnit. So go with NUnit if you plan to have nice automated tests.
We've been using xUnit.net. It seems to combine all the best of NUnit, MbUnit, and MSTest.
When I started unit testing, I started with NUnit as it is simple to set up and use. Currently I am using the built-in test runner that comes with ReSharper. That way, I can easily flip between code and test results. Incidentally, NUnit detects when you have compiled your code, so you do not need to do any refresh in NUnit. ReSharper automatically does a build when you choose to run a specific test.
Try also the PEX tool. It's Microsoft's own, probably soon to be integrated into VSTS. It does support NUnit, MbUnit and xUnit.net. I also use a small console application for testing one class or a small library. You could copy paste the code from here.
VSTT 2010 (Visual Studio Team System Test) should be a good bet if you are looking for functional test automation. Web services testing, UI testing, BizTalk testing and data-driven testing support. Please look at VSTT.
MbUnit is worth a look. It has a set of features comparable to NUnit. It has its own GUI, or can be integrated into Visual Studio if you have ReSharper. I would also recommend Rhino Mocks if you are doing any sort of TDD.
I would say MbUnit also. I like being able to run a single test many times just by specifying inputs and the result is right above the test function. It is a horrible description of what I mean, so here is a link that shows you what I mean.