C# .NET 测试框架建议
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.NET Testing Framework Advice
提问by saalon
I'm looking to introduce a unit testing framework into the mix at my job. We're using Visual Studio 2005 (though we may be moving to 2008 within the next 6 months) and work primarily in C#. If the framework has some kind of IDE integration that would be best, but I'm open to frameworks that don't have integration but are still relatively simple to get set up. I'm going to get resistance to it one way or another, so if I can make sure what I'm pushing isn't a pain in the neck, that would help my case.
我希望在我的工作中引入一个单元测试框架。我们正在使用 Visual Studio 2005(尽管我们可能会在接下来的 6 个月内迁移到 2008)并且主要使用 C# 工作。如果框架具有某种 IDE 集成,那将是最好的,但我对没有集成但设置起来仍然相对简单的框架持开放态度。我会以某种方式抵抗它,所以如果我能确保我推动的不是颈部疼痛,那将对我的情况有所帮助。
The obvious choice from the research I've done so far points to nUnit, but I'd like to get the impressions of someone who's actually used it before recommending it to my team.
到目前为止,我所做的研究中明显的选择指向 nUnit,但我想在向我的团队推荐它之前获得实际使用它的人的印象。
Has anyone out there used nUnit? If so, are there any pitfalls or limitations of which I should be aware? Are there other good options out there? If so, if you've used both nUnit at that, I'd greatly appreciate an idea of the strengths and weaknesses of them.
有没有人用过nUnit?如果是这样,是否有任何我应该注意的陷阱或限制?还有其他好的选择吗?如果是这样,如果您同时使用了 nUnit,我将非常感谢您了解它们的优点和缺点。
采纳答案by Karl Seguin
I think NUnit
isyour best bet. With TestDriven.NET
, you get great integration within VS.NET
. (Resharper also has a unit test runner if you're using it). NUnit
it simple to use and follows an established paradigm. You'll also find plenty of projects/tutorials/guides using it which always helps.
我认为NUnit
是你最好的选择。使用TestDriven.NET
,您可以在VS.NET
. (如果您正在使用它,Resharper 也有一个单元测试运行器)。 NUnit
它使用简单并遵循既定的范例。您还会发现大量使用它的项目/教程/指南,它们总是有帮助。
Your other main choice is probably MBUnit, which is more and more position itself as the BDD
framework of choice (in conjunction with Gallio http://www.gallio.org).
您的另一个主要选择可能是 MBUnit,它越来越多地将自己定位为BDD
首选框架(与 Gallio http://www.gallio.org结合使用)。
回答by Michael Stum
Scott Hanselman had a good Podcast about this, entitled:
Scott Hanselman 对此有一个很好的播客,标题为:
"The Past, Present and Future of .NET Unit Testing Frameworks"
“.NET 单元测试框架的过去、现在和未来”
:
:
回答by denny
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.
Visual Studio 2008
有一个内置的测试项目类型,其工作方式与 NUnit 类似,但显然与 NUnit 的集成更紧密Visual Studio
(可以在每个构建上运行,并在升级解决方案文件时以与转换结果页面类似的方式显示结果),但它显然不如 NUnit 成熟,因为它很新,我不确定它如何处理模拟。
But it would be worth looking into when your team moves to VS2008
但是当您的团队转移到 VS2008
回答by Dan
mbUnit
is worth alook, it has a set of features comparable to NUnit
, it has its own GUI, or can be integrated into VS
if you have Resharper
. I would also recommend Rhino Mocks
if you are doing any sort of TDD
.
mbUnit
值得一看,它有一组可比拟的功能NUnit
,它有自己的GUI,或者VS
如果你有的话可以集成到Resharper
. 我也建议Rhino Mocks
,如果你正在做任何形式的TDD
。
回答by Kevin Sheffield
I would say mbUnit also, I like being able to run a single test many times just by specifying inputs and result right above the test function. Horrible description of what I mean so here is a link that shows you what I mean.
我也想说 mbUnit,我喜欢能够通过在测试函数正上方指定输入和结果来多次运行单个测试。我的意思的可怕描述,所以这里有一个链接,向你展示我的意思。
回答by capgpilk
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.
Incidently 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.
当我开始单元测试时,我开始使用NUnit
它,因为它易于设置和使用,目前我使用的是随附的内置测试运行器Resharper
,这样我可以轻松地在代码和测试结果之间切换。顺便NUnit
检测您何时编译了代码,因此您无需在NUnit
. Resharper
当您选择运行特定测试时,会自动进行构建。
回答by qui
The built in unit testing in VS 2008
is alright, but its difficult to integrate with CruiseControl.net
, certainly a lot harder than normal NUnit
.
内置的单元测试还VS 2008
可以,但是很难集成CruiseControl.net
,肯定比正常的要困难得多NUnit
。
So go with NUnit
if you plan to have nice automated tests.
因此,NUnit
如果您打算进行良好的自动化测试,请继续。
回答by qui
回答by Yordan Georgiev
Try also PEXtool
It Microsoft's own probably soon to be integrated into VSTS
and does support NUnit
, MbUnit
and xUnit.net
也试试PEX工具它微软自己的可能很快就会被集成到 VSTS 中并且确实支持NUnit
,MbUnit
并且xUnit.net
I use also small Console Application for testing one class or small library. You could copy paste the code from here
我还使用小型控制台应用程序来测试一类或小型库。你可以从这里复制粘贴代码