C# .NET 单元测试包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1760/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 12:49:28  来源:igfitidea点击:

.NET Unit Testing packages?

提问by Orion Edwards

Getting back into a bit more .NET after a few-years of not using it full-time, and wondering what the good unit testing packages are these days.

在几年没有全职使用 .NET 之后重新开始使用 .NET,并且想知道现在有哪些好的单元测试包。

I'm familiar with NUnit (a few years ago), and have played briefly around with IronRuby, with the goal of getting something like rspec going, but don't know much beyond that.

我熟悉 NUnit(几年前),并曾短暂地使用过 IronRuby,目的是让诸如 rspec 之类的东西运行起来,但除此之外我一无所知。

I realize I could google for this and call it a day but I believe I'm likely to get a better and more informed response from asking a question here :-)

我意识到我可以为此在谷歌上搜索并收工,但我相信我可能会通过在这里提出问题得到更好、更明智的答复:-)

Suggestions?

建议?

采纳答案by Brad Tutterow

There are so many it's crazy. Crazy good, I guess.

有很多它是疯狂的。疯狂的好,我猜。

  • For the conservative types (me), NUnitis still available and still more than capable.
  • For the Microsoft-types, MSTestis adequate, but slow and clunky compared to Nunit. It also lacks code coverage without paying the big bucks for the pricey versions of Visual Studio.
  • There's also MbUnit. It's like NUnit, but has nifty features like RowTest (run the same test with different parameters) and Rollback (put the database back like you found it after a test)
  • And finally, xUnit.netis the trendy option with some attitude.
  • Oh, and TestDriven.NETwill give you IDE integration for both Nunit and MBunit.
  • 对于保守的类型(我)来说,NUnit仍然可用,而且仍然非常强大。
  • 对于 Microsoft 类型,MSTest就足够了,但与 Nunit 相比速度慢且笨重。它还缺乏代码覆盖率,而无需为昂贵的 Visual Studio 版本支付大笔费用。
  • 还有MbUnit。它类似于 NUnit,但具有 RowTest(使用不同参数运行相同的测试)和 Rollback(在测试后将数据库放回原样)等漂亮功能
  • 最后,xUnit.net是具有某种态度的时尚选择。
  • 哦,TestDriven.NET将为您提供 Nunit 和 MBunit 的 IDE 集成。

I'm sure they're all just fine. I'd steer away from MSTest though, unless you just enjoy the convenience of having everything in one IDE out of the box.

我相信他们都很好。不过,我会避开 MSTest,除非您只是享受在一个 IDE 中开箱即用的便利。

Scott Hanselmanhas a podcast on this very topic.

Scott Hanselman有一个关于这个主题的播客。

回答by Brett Veenstra

I like MbUnit, er, Gallio. Most importantly to me is having good tools support inside Visual Studio. For that I use Resharper, which has an MbUnit test runner. A lot of folks seem to like TestDriven.NETas their test runner as well.

我喜欢MbUnit,呃,Gallio。对我来说最重要的是在 Visual Studio 中拥有良好的工具支持。为此,我使用Resharper,它有一个MbUnit 测试运行器。很多人似乎也喜欢TestDriven.NET作为他们的测试运行器。

回答by Mike Minutillo

I like TestDriven.NET(even though I use ReSharper) and I'm pretty happy with XUnit.net. It uses Facts instead of Tests which many people dislike but I like the difference in terminology. It's useful to think of a collection of automatically provable Facts about your software and see which ones you violate when you make a change.

我喜欢TestDriven.NET(即使我使用 ReSharper)而且我对XUnit.net非常满意。它使用事实而不是许多人不喜欢的测试,但我喜欢术语上的差异。考虑一组有关您的软件的可自动证明的事实,并查看在进行更改时违反了哪些事实,这很有用。

Be aware that Visual Studio 2008 Professional (and above) now comes with integrated Unit Testing(it used to be available only with the Team System Editions) and may be suitable for your needs.

请注意,Visual Studio 2008 Professional(及更高版本)现在带有集成的单元测试(它曾经仅适用于 Team System 版本)并且可能适合您的需求。

回答by Orion Edwards

xUnit.net looks like it provides a slightly different approach to N/MB/MS/Unit, which is interesting.

xUnit.net 看起来它提供了一种与 N/MB/MS/Unit 略有不同的方法,这很有趣。

In my search for an rspec-like solution (because I LOVE the rspec), I also came across NSpec, which looks a bit wordy, but combined with the NSpec Extensionsaddon to use C#3 extension methods, it looks pretty nice.

在我寻找类似 rspec 的解决方案时(因为我喜欢 rspec),我也遇到了NSpec,它看起来有点罗嗦,但结合NSpec Extensions插件使用 C#3 扩展方法,它看起来很不错。

回答by Judah Gabriel Himango

We use NUnit and MBUnithere. We use TestDriven.NETto run the unit tests from within Visual Studio. We use the excellent, highly recommended RhinoMocksas a mock framework.

我们在这里使用 NUnit 和MBUnit。我们使用TestDriven.NET从 Visual Studio 中运行单元测试。我们使用优秀的、强烈推荐的RhinoMocks作为模拟框架。

回答by Lance Fisher

I used to use NUnit, but I switched to MbUnit since it has more features. I love RowTest. It lets you parametrize your tests. NUnit does have a litter bit better tool support though. I am using ReSharper to run MbUnit Tests. I've had problems with TestDriven.NET running my SetUp methods for MbUnit.

我曾经使用过 NUnit,但我改用了 MbUnit,因为它具有更多功能。我喜欢 RowTest。它可以让你参数化你的测试。不过,NUnit 确实有更好的工具支持。我正在使用 ReSharper 运行 MbUnit 测试。我在 TestDriven.NET 运行我的 MbUnit 设置方法时遇到了问题。

回答by Dan Blair

This is really a personal opinion on my part (I guess that's redundant since it is a forum). NUnit, MSTest, ect all do pretty mutch the same thing. However I find NMock indispensable.

这真的是我的个人意见(我想这是多余的,因为它是一个论坛)。NUnit、MSTest 等都做同样的事情。但是我发现NMock是必不可少的。

NMock or any mocking package is not unit testing but it makes it so much easier to do unit testing that it mught as well be.

NMock 或任何模拟包都不是单元测试,但它使单元测试变得更容易,它也应该如此。

回答by Iain Holder

Stick to NUnit. Don't go anywhere near MSTest.

坚持使用 NUnit。不要去MSTest附近的任何地方。

NUnit + ReSharper is an absolute joy to work with.

NUnit + ReSharper 使用起来绝对是一种乐趣。

回答by Doug R

I used to use NUnit, but now tend to use MbUnit, for two key features: 1. The RowTest feature allows you to easily run the same test on different sets of parameters, which is important if you really want thorough coverage. 2. The Rollback feature allows you to run tests against your database while rolling back changes after every test, keeping your database in exactly the same state every time. And it's as easy as adding the [Rollback] attribute.

我曾经使用 NUnit,但现在倾向于使用 MbUnit,有两个关键特性: 1. RowTest 特性允许您轻松地对不同的参数集运行相同的测试,如果您真的想要彻底覆盖,这一点很重要。2. 回滚功能允许您对数据库运行测试,同时在每次测试后回滚更改,使您的数据库每次都处于完全相同的状态。就像添加 [Rollback] 属性一样简单。

Another nice aspect of MbUnit is that its syntax is nearly identical to NUnit, so if you have a whole test bed already in place under NUnit, you can just switch out the references without the need to change any (very much?) code.

MbUnit 的另一个优点是它的语法几乎与 NUnit 相同,因此如果您在 NUnit 下已经有一个完整的测试平台,您可以只切换引用而无需更改任何(非常多?)代码。

回答by khebbie

I have made a small example of testing a .net lib using ironRuby: http://khebbie.dk/post/2008/08/Example-of-using-ironRubys-mini_rspec-library.aspx

我做了一个使用 IronRuby 测试 .net lib 的小例子:http://khebbie.dk/post/2008/08/Example-of-using-ironRubys-mini_rspec-library.aspx