单元测试、NUnit 还是 Visual Studio?

发布于 2024-08-07 16:33:37 字数 1431 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

弥枳 2024-08-14 16:33:38

NUnit 与 MS-Test

  1. Suite 属性相比没有什么优势 - 可以聚合测试并单独执行它们(例如,对于具有快速和慢速测试的大型项目很有用)
  2. 可读的 Assert 方法,例如 Assert.AreEqual(expected,actual) vs Assert.That(actual, Is.EqualTo(expected))
  3. NUnit 版本更新频繁 - MS-Test 每个 VS 版本只有一个。
  4. 许多集成运行程序,包括 Resharper 和 TestDriven.NET
  5. 预期异常消息断言 - 可以使用 NUnit 中的属性来完成,但必须使用 MS-Test
  6. [TestCase] 中的 Try-Catch 来完成! NUnit 允许进行参数化测试。

NUnit has few advantages over MS-Test

  1. Suite attribute - can aggregate tests and execute them separately (useful for large projects with fast and slow tests for example)
  2. Readable Assert method, e.g. Assert.AreEqual(expected, actual) vs Assert.That(actual, Is.EqualTo(expected))
  3. NUnit has frequent version updates - MS-Test has only one per VS version.
  4. Many integrated runners including Resharper and TestDriven.NET
  5. Expected exception message assertion - can be done using attribute in NUnit but must be done using Try-Catch in MS-Test
  6. [TestCase]! NUnit allows for parameter-ized tests.
小瓶盖 2024-08-14 16:33:38

从我目前的角度来看(经过 8 个月的开发,平均有 10 名开发人员),我建议反对使用 MSTest,原因如下

  • 框架本身是相当不错的
    慢的。我的意思不是测试代码
    你写的——这在你的控制之下。
    我的意思是运行这些的框架
    测试很慢,无论是运行
    测试套件、单个测试等。
  • 需要保留测试元数据文件
    这总是会导致并发症
    当几个开发人员正在工作时
    在其上(重新创建例如元数据
    ETC。)。其他所有测试套件都没有
    需要一个元数据文件。这是一种
    很高兴组织你的测试,但是你
    可以通过以下方式实现相同的目的
    命名空间、类和方法名称。
  • 进行持续集成时,如果您想在构建计算机上运行单元测试,则需要在该计算机上安装 Visual Studio。

换句话说,如果 8 个月前我必须再次做出决定,我可能会选择 NUnit。我可能没有集成的测试结果报告,但开发人员将拥有更无缝的测试体验。

From my current perspective (after 8 months of development with about 10 developers on average) I would advise against using MSTest for the following reasons

  • The framework in itself is quite
    slow. I don't mean the test code that
    you write - that's under your control.
    I mean the framework running those
    tests is slow, whether it's running a
    test suite, single tests etc.
  • The need to keep a Test-Metadata file
    which always leads to complications
    when several developers are working
    on it (recreating e.g. the metadata
    etc.). Every other test suite doesn't
    need a metadata file. It is kind of
    nice to organize your tests but you
    can achieve the same through
    namespaces, classes and method names.
  • Doing Continuous Integration, if you want to run unit tests on your build machine you will need to install Visual Studio on that machine.

In other words, if I would have to decide again 8 months ago, I would probably take NUnit. I may not have the integrated test results report, but developers would have a more seamless testing experience.

丢了幸福的猪 2024-08-14 16:33:38

这是我使用 MS Test 的经验

  • 我们正在运行大约 3800 个测试的 MS Test。
  • 测试需要很长时间才能开始执行,这在运行单个测试时会很痛苦。
  • 执行测试需要大约 1GB 内存。不,这不是由于我们的测试中的内存泄漏造成的。我们经常遇到 OutOfMemoryExceptions。
  • 因为它使用那么多资源,所以我们开始从批处理文件执行测试。那么整个集成有什么好处呢?
  • 它有缺陷且不稳定:
    • 例如,如果您从测试中删除 [Ignore] 属性,它不会识别它,因为它会在某处缓存有关测试的信息。您需要刷新测试列表,这有时可以解决问题,或者重新启动 VS。
    • 它不会随机地将引用程序集复制到out目录。
    • 部署项目(要使用的其他文件)无法正常工作。它们会被随机忽略。
  • vsmdi 和 testrunco​​nfig 文件中有隐藏的(在测试代码中不可见)信息。如果你不关心它,它可能不起作用。
  • 从功能上来说,它可能与 NUnit 相当,但如果您考虑使用 VS 测试器版本,它会非常昂贵。

补充:我们现在还有一些测试,甚至无法说出有多少。由于 OutOfMemoryExceptions 和其他不稳定问题,不可能再从 Visual Studio 运行它们。我们从脚本运行测试。在 Visual Studio 中查看测试结果很容易,但是当解决方案打开时,VS 崩溃(每次)。因此我们需要使用文本搜索来搜索失败的测试。集成工具不再有任何优势。


另一个更新:我们现在使用 VS 2013。很多事情都改变了。自我们开始以来,他们第三次重写了 MS Test 测试运行程序。这导致了很多重大变化,但两个新版本都没有做得更好。我们很高兴没有使用 MS Test 的奇特功能,因为它们都不再受支持。实在是太可惜了。我们仍然使用脚本来构建和运行所有单元测试,因为它更方便。 Visual Studio 需要几分钟才能开始运行测试(编译后直到第一次测试开始的时间测量)。他们可能通过更新修复它,这可能是我们项目的特定问题。然而,在运行相同的测试时,Resharper 的速度要快得多。

结论:至少与Resharper结合使用时,MS Test是有用的。我希望他们最终能弄清楚测试运行程序应该如何编写,并且在我们下次更新 Visual Studio 时不会进行此类重大更改。

Here is my experience with MS Test

  • We are running MS Test with around 3800 Test.
  • It takes very long for the tests just to start executing, which is painful when running single tests.
  • It takes around 1GB Memory to execute the tests. No, it is not due to memory leaks in our tests. Frequently we run into OutOfMemoryExceptions.
  • Because it uses that much resource, we are starting to execute the tests from batch-files. So what's the whole integration good for?
  • It is buggy and unstable:
    • For instance, if you remove the [Ignore] Attribute from a test, it does not recognize it, because it caches information about tests somewhere. You need to refresh the testlist, which sometimes solves the problem, or restart VS.
    • It randomly does not copy reference assemblies to theout directory.
    • Deployment Items (additional files to be used) just don't work properly. They are ignored randomly.
  • There is hidden (not visible in the test code) information in vsmdi and testrunconfig files. If you don't care about it, it might not work.
  • Functionally it might be comparable to NUnit, but it is very expensive if you consider using VS tester edition.

Addition: We have some more tests now, can't even say how many. It is impossible to run them all anymore from Visual Studio, because of OutOfMemoryExceptions and other instability problems. We run the tests from scripts. It would be easy to view test results in Visual Studio, but when the solution is open, VS crashes (every time). So we need to search the failing tests using text search. There is no advantage of an integrated tool anymore.


Another Update: We are using VS 2013 now. A lot of things changed. They rewrote the MS Test test runner for the third time since we started. This caused a lot of breaking changes, but neither new version was doing anything better. We are glad that we didn't use the fancy features of MS Test, because they are all not supported anymore. It's really a shame. We are still using scripts to build and run all unit tests, because it is handier. Visual Studio required a few minutes to start running tests (time measures after compilation until first test starts). They probably fixes it with an update and this might be a specific problem of our project. However, Resharper is much quicker when running the same tests.

Conclusion: At least in combination with Resharper, MS Test is useful. And I hope that they finally find out how the test runner should be written and won't do this kind of breaking changes when we update Visual Studio next time.

心不设防 2024-08-14 16:33:38

NUnit 可以与 Visual Studio 结合使用。它是一个框架而不是一个单独的程序。所以你可以关心一下它是否适合你:)。

替代文本
(来源:codeplex.com)

“安装插件后,您将在工具菜单下找到一个新的子菜单。”

有关导入它的更多信息,请参阅 http://nunitit.codeplex.com/

另外,通过SO的搜索可以找到很多东西。 这个例如,主题列出了 NUnit 相对于 MS 标准测试的优势。

NUnit can be used in combination with visual studio. It is a framework not a separate program. So you could care an see if it suits you :).

alt text
(source: codeplex.com)

"After installing the plugin you'll find a new submenu under the tools menu."

See http://nunitit.codeplex.com/ for more information on importing it.

Also, a lot can be found using the search of SO. This topic lists advantages of NUnit over MS standard testing for instance.

月亮邮递员 2024-08-14 16:33:38

MS-Test 相对于 NUnit 的最大优势是 MS-Test 可以使用反射生成模拟对象。
我发现它非常有用

Biggest advantage MS-Test over NUnit is MS-Test can generate mock objects using Reflection.
I found it very usefull

浅沫记忆 2024-08-14 16:33:38

NUnit 可与 VS 标准版配合使用。

NUnit works with the Standard edition of VS.

如果没有 2024-08-14 16:33:38

我不确定其他人,但 NUnit 提供了很好的 GUI 和控制台来运行您的单元测试,您还可以生成 NUnit 测试执行结果的报告,该报告将提供测试是否失败或通过以及测试时间的详细信息参加单元测试

I am not sure of others but NUnit provides nice GUI and console to run your Unit Tests and also you can generate report of the result of NUnit Test execution which would give the detail of whethere the test has failed or passed and also what time did it take for your unit test

掩耳倾听 2024-08-14 16:33:38

NUnit 是一个单元测试框架,resharper 也支持它。我认为你使用的是微软的单元测试框架,所以NUnit只是微软产品的替代品;)

这里是NUnit主页的链接: http://nunit.org

NUnit is a unit testing framework, which is also supported by resharper. I think you are using Microsoft's unit testing framework, so NUnit is just an alternative to Microsoft's product ;)

Here is the link to the homepage of NUnit: http://nunit.org

五里雾 2024-08-14 16:33:38

NUnit 中,测试不是并行执行的。相反,似乎所有测试都在单个线程上执行。在 MSTest 中,每个测试都在单独的线程上实例化,这导致运行交错。因此,如果测试 A 的成功依赖于测试 B,则它可能会失败,因为测试 B 可能会在测试 A 运行时开始运行。

In NUnit, tests are not executed in parallel. Rather, it appears that all tests execute on a single thread. In MSTest, each test is instantiated on a separate thread, this results the runs being interleaved. Therefore, if test A depends on test B for its success, it likely will fail as test B will likely start running as test A is running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文