我将在工作中开始一个新项目,并想进入单元测试。我们将使用Visual Studio 2008, c#和ASP。NET MVC之类的东西。我正在考虑使用NUnit或Visual Studio 2008的内置测试项目,但我也愿意研究其他建议。是一种系统比另一种更好,还是比另一种更容易使用/理解?
我希望让这个项目成为我们未来发展努力的“最佳实践”。
我将在工作中开始一个新项目,并想进入单元测试。我们将使用Visual Studio 2008, c#和ASP。NET MVC之类的东西。我正在考虑使用NUnit或Visual Studio 2008的内置测试项目,但我也愿意研究其他建议。是一种系统比另一种更好,还是比另一种更容易使用/理解?
我希望让这个项目成为我们未来发展努力的“最佳实践”。
当前回答
我更喜欢使用MS的小测试框架,但现在我坚持使用NUnit。多发性硬化的问题通常是(对我来说)
必须维护的共享“测试”文件(无意义) 测试列表会与多个开发人员/ vcs产生冲突 糟糕的集成UI -令人困惑的设置,繁重的测试选择 没有好的外部流道
警告
如果我正在测试一个aspx站点,我肯定会使用MS的 如果我是独自开发,MS也可以 如果我的技能有限,不能配置NUnit:)
我发现编写我的测试并启动NUnitGUI或其他前端(testDriven的价格非常非常非常昂贵)要容易得多。使用命令行版本设置调试也非常简单。
其他回答
单元测试框架实际上并不重要,因为你可以用单独的项目文件和条件编译转换测试类(就像这样,Visual Studio→NUnit):
#if !NUNIT using Microsoft.VisualStudio.TestTools.UnitTesting; #else using NUnit.Framework; using TestClass = NUnit.Framework.TestFixtureAttribute; using TestMethod = NUnit.Framework.TestAttribute; using TestInitialize = NUnit.Framework.SetUpAttribute; using TestCleanup = NUnit.Framework.TearDownAttribute; using TestContext = System.String; using DeploymentItem = NUnit.Framework.DescriptionAttribute; #endif
TestDriven。Net插件很好,不是很贵…对于普通的Visual Studio 2008,你必须从你的测试类或测试列表中找到测试。TestDriven。Net中,您可以直接从正在测试的类中运行测试。毕竟,单元测试应该易于维护,并且离开发人员很近。
xUnit是新项目的另一种可能。它的语法可能更直观,但它与其他框架并不兼容。
我不喜欢Visual Studio的内置测试框架,因为它迫使你创建一个单独的项目,而不是把你的测试作为你正在测试的项目的一部分。
Visual Studio 2008内置单元测试框架的优点/变化:
The 2008 version now is available in professional editions (before it required expensive versions of Visual Studio, and this is just for developer unit testing) that left a lot of developers with the only choice of open/external testing frameworks. Built-in API supported by a single company. Use the same tools to to run and create tests (you may run them using the command line also MSTest). Simple design (granted without a mock framework, but this is a great starting point for many programmers). Long term support granted (I still remember what happened to NDoc, and I don't want to commit to a testing framework that might not be supported in five years, but I still consider NUnit a great framework). If using Team Foundation Server as your backend, you can create work items or bugs with the failed test data in a simple fashion.
如果你正在考虑MSTest或NUnit,那么我建议你看看MbUnit。我的理由是
TestDriven.Net compatibility. Nothing beats have TestDriven.Net.ReRunWithDebugger bound to a keyboard combination. The Gallio framework. Gallio is a test runner like NUnit's. The only difference is it doesn't care if you wrote your tests in NUnit, MSTest, xUnit or MbUnit. They all get run. Compatibility with NUnit. All features in NUnit are supported by MbUnit. I think you don't even need to change your attributes (will have to check that), just your reference and usings. Collection asserts. MbUnit has more Assert cases, including the CollectionAssert class. Basically you no longer need to write your own tests to see if two collections are the same. Combinatorial tests. Wouldn't it be cool if you could supply two sets of data and get a test for all the combinations of data? It is in MbUnit.
我最初选择MbUnit是因为它的[RowTest ....我找不到一个回去的理由。我把我所有的活动测试套件从NUnit移过来,再也没有回头。从那时起,我已经将两个不同的开发团队转换为收益。