Ms Test 还是 NUnit?
与内置的 MsTest 相比,选择 NUnit 进行单元/集成测试有什么优势吗?
Is there any advantage to picking NUnit for unit/integration testing vs the built in MsTest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们非常相似。差异是微妙的。
您可以编写
而不是编写 4 个测试或在测试中使用循环。失败测试的错误消息将更加清晰,并且测试结果将始终方便地分组。
例如,
这相当于运行测试
(请参阅原始页面 此处)
MSTest 始终为每个正在执行的测试方法实例化测试类的新实例。这非常有用,因为在每个单独的测试之前,将运行 Setup 和 TearDown 方法,并且将重置每个实例变量。使用 NUnit,您必须处理最终在测试之间共享的实例变量(尽管这不应该是一个大问题:设计良好的测试应该通过设计进行隔离)
使用 NUnit,抽象类可以是测试装置,并且您可以继承其他测试装置。 MsTest没有这个功能。
MSTest 与 Visual Studio 集成良好。您需要第三方插件才能有效地使用 NUnit,例如 ReSharper、测试驱动 .NET 或 NCrunch
NUnit 有一个流畅版本的 Assert,因此您可以编写
示例
,而不是
使用 SharpTestEx 您甚至可以编写:
并利用强类型 IntelliSense。
They are pretty similar. Differences are subtle.
You can write
rather than writing 4 tests or using a cycle inside the test. Failing tests' error messages will be much clearer and test results will be always conveniently grouped.
For example
which is equivalent to running the tests
(see the original page here)
MSTest always instantiates a new instance of the test class for each test method being executed. This is very useful, since prior to each single test, Setup and TearDown methods will be run and every instance variables will be reset. With NUnit you have to take care of instance variables eventually shared between tests (though this shouldn't be a big issue: a well designed test should be isolated by design)
With NUnit an abstract classes can be a test fixtures and you can inherit other test fixtures from it. MsTest does not have this feature.
MSTest is well integrated with Visual Studio. You'd need a third party plugin to effectively work with NUnit, for example ReSharper, Test Driven .NET or NCrunch
NUnit has a fluent version of Assert, so you can write
for example
rather than
With SharpTestEx you can even write:
and take advantage of the strong typed IntelliSense.