NUnit(和 MSTest)如何处理更改静态/共享变量的测试?
我有一些使用共享网关模式来实现控制反转容器的代码。 我有数百个 NUnit 单元测试来练习使用此 IOC 的代码。 它们都可以工作(在我的机器上!),但我担心这些测试可能会在负载下失败。 我似乎记得 NUnit(和 MSTest)尝试在多个线程上并行运行测试(这肯定会触发静态/共享网关上的竞争条件),但我找不到任何说明实际发生情况的文档。 我的经验是,NUnit 似乎是按顺序运行测试的。 我的问题是,NUnit(或 MSTest)是否曾经并行运行单元测试? 如果可以,在什么条件下? 而且,我可以通过某种配置选项将其关闭吗?
I have some code that uses the shared gateway pattern to implement an inversion of control container. I have several hundred NUnit unit tests that exercises the code that uses this IOC. They all work (on my machine!) but I am concerned that these tests might fail under load. I seem to remember that NUnit (and MSTest) attempts to run tests in parallel on multiple threads (which would definitely trigger race conditions on the static/shared gateway) but I cannot find any documentation that says what actually happens. My experience is that NUnit seems to be running the tests sequencially. My question is, does NUnit (or MSTest) ever run unit tests in parallel? If so, under what conditions? And, can I turn this off via some sort of configuration option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:
Visual Studio 2010 引入了并行运行测试的功能。
这是分步文章介绍如何启用此功能。
MsTest:
因此,根据 Microsoft Visual Studio Team System 的 David Williamson 在 上的说法MSDN 论坛中的这篇文章:
此外,使用 MsTest 运行的测试每次都使用不同的线程运行,以确保每个测试都有一个干净的记录。 没有办法禁用此行为。
NUnit:
NUnit 在同一线程上运行所有测试。
Update:
Visual Studio 2010 introduced the ability to run tests in parallel.
Here is a step by step article about how to enable this.
MsTest:
So according to David Williamson, from Microsoft Visual Studio Team System, on this post in the MSDN forums:
Also, tests run using MsTest are each run using a different thread in order to ensure that you have a clean slate for each test. There is no way to disable this behavior.
NUnit:
NUnit runs all tests on the same thread.