C# 哪个单元测试框架?

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

Which unit testing framework?

c#.netunit-testing

提问by Tony The Lion

I wondered which unit testing framework would be a good one to get really familiar with? I know this might be a question of opinion, but I thought I'd ask anyways. I know that I will need to do it someday, so I might as well learn to use it. I know that there is quite a few out there, but which one is effective for C# development?

我想知道哪种单元测试框架是真正熟悉的好框架?我知道这可能是一个意见问题,但我想我还是会问。我知道总有一天我需要这样做,所以我不妨学会使用它。我知道那里有很多,但哪一种对 C# 开发有效?

From thisquestion I can see that unit testing is necessary, but personally I haven't used it. So that's why I ask this question.

这个问题我可以看出单元测试是必要的,但我个人没有使用它。所以这就是我问这个问题的原因。

采纳答案by Adriaan Stander

I would go with NUnit.

我会和NUnit一起去。

Some links: NUnit QuickStart, NuGet Package

一些链接: NUnit 快速入门NuGet 包

回答by Aaronaught

Personally, I prefer the Visual Studio Unit Testing Framework, for two main reasons:

就个人而言,我更喜欢 Visual Studio 单元测试框架,主要有两个原因:

  • It integrates seamlessly with the IDE;
  • It's one less program to deploy in a dev environment.
  • 它与IDE无缝集成;
  • 在开发环境中部署的程序少了一个。

Having said that, pretty much any unit testing framework will do the trick, the important thing is to have tests!

话虽如此,几乎任何单元测试框架都可以做到这一点,重要的是要有测试!

回答by Luhmann

Don't get stuck on choosing a framework. Just pick one and start testing - they're not all that different. When you have written tests for a while, you will know what to look for, to suit your needs.

不要纠结于选择框架。只需选择一个并开始测试 - 它们并没有什么不同。当您编写测试一段时间后,您就会知道要寻找什么来满足您的需求。

Personally, I have found xUnit, Testdriven.Netand Moqto be a very flexible set of test tools.

就我个人而言,我发现xUnitTestdriven.NetMoq是一组非常灵活的测试工具。

Also see this post: NUnit vs. MbUnit vs. MSTest vs. xUnit.net

另见这篇文章:NUnit vs. MbUnit vs. MSTest vs. xUnit.net

回答by Zachary Scott

There are a few reasons for testing, thus a few testing environments. Plus, there are levels of testing, like simple, stubs, and mocks. For example, you could test behavior rather than state.

测试有几个原因,因此有几个测试环境。此外,还有测试级别,如简单、存根和模拟。例如,您可以测试行为而不是状态。

As far as function, I usually use the Visual Studio built in setup, add a reference to the NUnit dll, and change the c# annotations to be NUnit. This is because I like testing outside of Visual Studio, especially when it involves others on my team (and we didn't buy the team edition of VS yet).

功能方面,我一般使用Visual Studio自带的setup,添加对NUnit dll的引用,将c#注解改成NUnit。这是因为我喜欢在 Visual Studio 之外进行测试,尤其是当它涉及到我团队中的其他人时(而且我们还没有购买 VS 的团队版)。

回答by Robert Rossney

I use NUnit for the testing framework and ReSharper for integrating it into VS (and everything else ReSharper does).

我使用 NUnit 作为测试框架,使用 ReSharper 将其集成到 VS(以及 ReSharper 所做的一切)。

回答by maxname

Use MbUnit (with Gallio), NUnit, MsTest or xUnit. You can combine several unit tests. I use NUnit for TDD

使用 MbUnit(与 Gallio)、NUnit、MsTest 或 xUnit。您可以组合多个单元测试。我将 NUnit 用于 TDD

回答by mythz

I've decided to stick with NUnit because ReSharper provides native IDE support (which saves a lot of time). It's also supported by TeamCity in running and reporting automated tests.

我决定坚持使用 NUnit,因为 ReSharper 提供本机 IDE 支持(这可以节省大量时间)。TeamCity 还支持它运行和报告自动化测试。