有什么我可以在 NUnit 中做但在 MSTest 中不能做的事情吗?
这个问题已经在许多不同的论坛上以各种形式提出,但是,恕我直言,我一直无法找到一个真正明确回答这个问题的地方,所以我将重新构建它并再次询问它。
我基本上在一家微软商店工作。我们使用 TFS,并且所有开发人员都订阅了 MSDN,包括 VS 的 Team Suite 版本。这样我们就可以访问MSTest了。
我阅读了各种 NUnit 与 MSTest 的比较,开发人员社区似乎绝大多数选择了 NUnit。但给出的理由似乎从来都不是压倒性的或令人信服的,至少对于我们的情况来说是这样。 (NUnit 更新更频繁,NUnit 更快,NUnit 不需要 TFS 等)
如果我选择,我可以使用 NUnit,但必须捍卫在没有正式支持的情况下使用开源软件的行为。我需要一个相当令人信服的理由才能这样做。
为了证明使用 NUnit 而不是 MSTest 的合理性,我基本上必须回答的是:有什么是我在 NUnit 中可以做而在 MSTest 中无法做的事情吗?
This question has been asked in various forms in a number of different forums, but, IMHO, I haven't been able to find a place where it's really answered clearly, so I'm going to reframe it and ask it again.
I work in a basically Microsoft Shop. We use TFS, and all of our developers have MSDN subscriptions including the Team Suite edition of VS. So we have access to MSTest.
I've read the various NUnit vs. MSTest comparisons, and the developer community seems to pretty much overwhelmingly choose NUnit. But the reasons given don't ever seem to be overwhelming or compelling, at least to our situation. (NUnit is updated more often, NUnit is faster, NUnit doesn't require TFS, etc.)
I can use NUnit if I choose, but the use of open source software without a formal support behind it has to be defended. I need a fairly compelling reason to do so.
What I basically have to answer to justify using NUnit in preference to MSTest is this: is there anything that I can do in NUnit that I can't do with comparable effort in MSTest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
Roy,你的一些信息已经过时了,尤其是与 2010 年相关的信息;
这可以使用 2010 年的单元测试扩展性来实现。
正确那仍然存在
Jim 在执行 MSTest 的同时为 MSTest 实现了 Assert.Throws 的一个版本NUnit 的原始实现,NUnit 已包含在后续版本中,MSTest 尚未包含,但仍然可以使用。
其中有几个由第三方为 MSTest 实现
请参阅 Jamie 的评论,他已设法使 MSTest 运行得更快:-)
不是在 2010 年,内置了 64 位支持。
这可以工作,但不能跨程序集,这确实限制了它的实用性。
仍然存在
正确的是,有很多误解认为 MSTest 与 Nunit 相同,但 MSTest 是一个通用框架。
正确的是,有一个 XML 配置设置允许控制并行度。
Roy, Bunch of your information is out of date especially as it relates to 2010;
This can be implemented using unit test extensibility in 2010.
Correct thats still there
Jim implented a version of Assert.Throws for MSTest at the same time as he did the original implementation for NUnit, NUnit has included in subsequent releases, MSTest has not, its still possible to use though.
There are several of these implemented by 3rd parties for MSTest
See Jamie's comment he has managed to get MSTest running faster :-)
Not in 2010, 64 bit support is built in.
This works but not across assemblies which does limit its usefulness.
Still there
Correct, there is a lot of misconception that MSTest is the same as Nunit but MSTest is a generalized framework.
Correct there is an XML config setting that allows control of degree of parallelism.
NUnit 有一个更丰富的断言 API。该 API 特别优雅(甚至流畅),例如,
如果您看过 Hamcrest< /a> JUnit 的扩展,您会认出这种风格。
它还具有不断增长的扩展集,例如性能测试和优秀的 VS 插件。
NUnit has a richer assert API. The api is particularly elegant (fluent, even), for example
If you've seen the Hamcrest extensions to JUnit you'll recognise this style.
It also has a growing set of extensions, such as performance testing and an excellent VS plugin.
我可以向您推荐一些有关 MSTest 的挫败感的博客:
公平地说,这些人正在尝试在非 TFS 构建服务器上设置 MSTest 。他们的一些问题不适用于您的情况。
我们主要是一家 Microsoft 商店,并使用 TFS 进行源代码控制。但是,我们使用 TeamCity 进行持续集成;我们喜欢它,并且它与 TFS 集成得相当好。我从未使用过 MSTest;我们已经使用 NUnit 多年了,并且没有看到任何改变的理由。
MSTest 应该与 Team Suite 紧密集成,这(因为您的公司已经为此支付了高昂的费用)是对其有利的一点。
NUnit 的供应商锁定较少,并且具有丰富的 API。正如 serg10 所指出的,Assert.That 语法特别强大且优雅。
最后,您可以编写良好的单元测试,而无需所有花哨的功能。其中一些甚至可能会妨碍(这是 xUnit.net 背后的理论)。我建议您的团队标准化一个测试框架;避免一些代码在 MSTest 中,而其他代码在 NUnit 中。
我认为编写好的测试比选择框架更重要。考虑阅读单元测试的艺术:.NET 中的示例,编写一些测试,然后看看 MSTest 是否足以满足您团队的需求。
编辑:《单元测试的艺术》附录 B 对 Microsoft 的单元测试框架有一些很好的评论。它提到 YUnit 作为扩展 MSTest 有多么麻烦的示例。然而,由于紧密集成,作者确实建议 Team System 用户使用 MSTest。
I can point you to a couple of blogs on frustrations with MSTest:
To be fair, these people are trying to set up MSTest on non-TFS build servers. Some of their issues are not going to apply to your situation.
We are primarily a Microsoft shop, and use TFS for source control. However, we use TeamCity for Continuous Integration; we like it, and it integrates reasonably well with TFS. I've never used MSTest; we've been using NUnit for years, and have seen no reason to change.
MSTest is supposed to have tight integration with Team Suite, which (since your company has already paid the outrageous fee for that) is a point in its favor.
NUnit comes with less vendor lock-in, and has a rich API. As serg10 pointed out, the Assert.That syntax is particularly powerful and elegant.
In the end, you can write good unit tests without all the fancy features. Some of them may even get in the way (which is the theory behind xUnit.net). I would recommend that your team standardize on one test framework; avoid having some code in MSTest and other code in NUnit.
I think writing good tests is more important than your choice of frameworks. Consider reading The Art of Unit Testing: with Examples in .NET, writing some tests, then seeing if MSTest is adequate for your team's needs.
EDIT: Appendix B of The Art of Unit Testing has some good comments on Microsoft's Unit Testing Framework. It mentions YUnit as an example of how cumbersome it is to extend MSTest. However, the author does suggest MSTest for Team System users due to the tight integration.
我在 MsTest 和 NUnit 之间有一个很好的方法。
您可以使用 MSTest 框架来运行测试(每个测试的 TestClass 属性和 TestMethod 属性),但使用 NUnit Assert API。
只需这样做:
现在您可以使用 Assert.That(..) 并且仍然拥有 TFS 自动构建和测试报告。
你的测试可以在VS、TestDriven.net或Resharper中运行,没关系,测试会失败或正确通过,失败输出将根据NUnit框架。
参见这里:
http:// /alsagile.com/archive/2010/03/09/stop-the-war- Between-nunit-and-mstest-make-them.aspx
I have a nice way in between MsTest and NUnit.
You can use the MSTest framework to run your test (TestClass attribute and TestMethod attribute for each test) but use the NUnit Assert API.
just do this :
now you can use Assert.That(..) and still have TFS automated build and test report.
your test can be run in VS, TestDriven.net or Resharper, it doesnt matter, the test will fail or pass correctly, and the fail output will be according to NUnit framework.
see here :
http://alsagile.com/archive/2010/03/09/stop-the-war-between-nunit-and-mstest-make-them.aspx
我在将我们从 MSTest 切换到 NUnit 时发现了这个问题,因为由于 MSTest,我们无法再信任 CI 构建的结果。切换到 NUnit 将使我们(最终)相信 CI 构建失败是真实的,而不是另一个 MSTest 故障。这是真正的答案——只有使用 NUnit(或其他一些非 MSTest 测试运行程序)我们才能信任我们的 CI 构建。
I found this question as I am switching us to NUnit from MSTest because we can't trust the result of our CI build anymore because of MSTest. Switching to NUnit will allow us to (finally) trust that a CI build failure is real, not another MSTest glitch. This is the real answer--only with NUnit (or some other non-MSTest test runner) can we trust our CI build.
请仔细阅读 ExpectedExceptionAttribute 文档,没有任何地方说明测试异常消息,因此这不是未断言的错误。
第二个参数是未抛出预期异常类型时显示的断言消息,而不是预期异常消息。即像 Assert.IsTrue(condition, message) 中的第二个参数一样。
Please read ExpectedExceptionAttribute documentation carefully, it is nowhere stated that tests the exception message so it's not a bug that is not asserted.
The second parameter is the assert message what is displayed when expected exception type is not thrown, not the expected exception message. I.e. like the second parameter in Assert.IsTrue(condition, message).
我一直致力于 TestDriven.Net 3.0 中对 MSTest 的一流支持。在以前的版本中,MSTest 支持非常基本(似乎很少有人使用 MSTest)。
从 TestDriven.Net 3.0 Beta 2 开始,对 MSTest 的所有单元测试相关属性都有相当全面的支持。甚至还支持使用 DataSource 属性的数据驱动测试。您的测试也将以接近 NUnit 的速度执行!
如果您使用 MSTest,我很想知道在使用 TestDriven.Net 3.0 Beta 2(或更高版本)执行时是否有任何单元测试失败。
请在您的 MSTest 项目中尝试一下,并让我知道您的进展情况:
http://www.testdriven.net/download.aspx
注意,它不支持DeploymentItem 或 HostType 属性。您可以使用“复制到输出目录”项目项设置而不是 DeploymentItem。
I've been working on first class support for MSTest in TestDriven.Net 3.0. In previous versions the MSTest support was very basic (there seemed to be few people using MSTest).
As of TestDriven.Net 3.0 Beta 2, there is pretty comprehensive support for all of the unit testing related attributes of MSTest. There is even support for data driven tests using the DataSource attribute. Your tests will also execute at close to NUnit speeds!
If you use MSTest, I'd be interested to hear if any of your unit tests fail when executed using TestDriven.Net 3.0 Beta 2 (or later).
Please try it on your MSTest projects and let me know how you get on:
http://www.testdriven.net/download.aspx
NOTE, it doesn't support the DeploymentItem or HostType attributes. You can use the 'Copy to Output Directory' project item setting instead of DeploymentItem.
您可以更改 NUnit 中的代码,因为它是开源的。 MSTest 无法做到这一点。
You can change the code in NUnit because it is open source. You can't do that with MSTest.
请参阅 http:// Fluentassertions.codeplex.com。你可以做类似的事情
See http://fluentassertions.codeplex.com. You can do stuff like
@戴夫·汉纳
MS Test 开箱即用,因此减少了一个需要担心部署和保持更新的组件。
它还在设计上与 Visual Studio 和其他 Microsoft 产品集成。
流畅的语法很好,但它不是功能上的差异,所以我会忽略它。更不用说您可以通过使用扩展库在 MS Test 中拥有相同的功能。
表现。 99% 的测试性能由被测系统控制,因此即使两个库之间有 100% 的性能差异,也会导致性能的总体差异可以忽略不计。
开源与非开源:您从使用开源库中受益的机会很小。例外情况是当更改经常被拉入主干或有足够的资源来保持修改的分支更新时。
@Dave Hanna
MS Test is available out of the box so one less component to worry about deploying and keeping updated.
It is also integrated with Visual Studio and other Microsoft products by design.
The fluent syntax is nice but it's not a functional difference so I'd ignore it. Not to mention that you can have the same in MS Test by using an extension library.
Performance. 99% of test performance is controlled by system under test, so even a 100% performance difference between two library would result in an ignorable overall difference in performance.
Open source vs. not open source: the chances that you'll benefit from using an open source library are minimal. The exceptions are when changes are pulled into trunk frequently or when there are enough resources to keep the modified branch updated.
您可以非常轻松地使用 Mono 在 Linux 上运行 NUnit 测试,但我认为您不能通过 MSTest 测试来做到这一点。
You can very easily run NUnit tests on Linux with Mono and I don't think you can do that with tests for MSTest.