我将在工作中开始一个新项目,并想进入单元测试。我们将使用Visual Studio 2008, c#和ASP。NET MVC之类的东西。我正在考虑使用NUnit或Visual Studio 2008的内置测试项目,但我也愿意研究其他建议。是一种系统比另一种更好,还是比另一种更容易使用/理解?
我希望让这个项目成为我们未来发展努力的“最佳实践”。
我将在工作中开始一个新项目,并想进入单元测试。我们将使用Visual Studio 2008, c#和ASP。NET MVC之类的东西。我正在考虑使用NUnit或Visual Studio 2008的内置测试项目,但我也愿意研究其他建议。是一种系统比另一种更好,还是比另一种更容易使用/理解?
我希望让这个项目成为我们未来发展努力的“最佳实践”。
当前回答
如果你正在考虑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移过来,再也没有回头。从那时起,我已经将两个不同的开发团队转换为收益。
其他回答
有点偏离主题,但如果你使用NUnit,我可以推荐使用ReSharper -它为Visual Studio UI添加了一些按钮,使它更容易在IDE中运行和调试测试。
这篇评论略显过时,但更详细地解释了这一点:
使用ReSharper作为TDD工具包的重要部分
如果你正在考虑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移过来,再也没有回头。从那时起,我已经将两个不同的开发团队转换为收益。
我不喜欢Visual Studio的内置测试框架,因为它迫使你创建一个单独的项目,而不是把你的测试作为你正在测试的项目的一部分。
与NUnit相比,我对Visual Studio单元测试的主要不满是Visual Studio测试创建倾向于为私有成员访问注入一堆生成的代码。
有些人可能想测试他们的私有方法,有些人可能不想。那是另一个话题了。
我担心的是,当我编写单元测试时,它们应该被严格控制,这样我才能确切地知道我在测试什么以及我如何测试它。如果有自动生成的代码,我就失去了一些所有权。
xUnit是新项目的另一种可能。它的语法可能更直观,但它与其他框架并不兼容。