NUnit(和MSTest)如何处理更改静态/共享变量的测试? [英] How does NUnit (and MSTest) handle tests that change static/shared variables?

查看:125
本文介绍了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?

推荐答案

更新:

Visual Studio 2010引入了并行运行测试的功能.

Visual Studio 2010 introduced the ability to run tests in parallel.

这是 MsTest:
因此,根据Microsoft Visual Studio Team System的David Williamson的说法,它位于
MSDN论坛中的这篇文章:

MsTest:
So according to David Williamson, from Microsoft Visual Studio Team System, on this post in the MSDN forums:

测试绝对不能在 在VS或通过VS运行时并行 mstest.exe.如果它们在 通过VS进行负载测试,那么这是一个 不同的故事.基本执行 但是,它始终是串行的.

Tests absolutely do NOT run in parallel when run in VS or via mstest.exe. If they are run in a Load Test through VS then that is a different story. Basic execution, however, is always serial.

此外,使用MsTest运行的测试每个都使用不同的线程运行,以确保每个测试的表盘都是干净的.无法禁用此行为.

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在同一线程上运行所有测试.

NUnit:
NUnit runs all tests on the same thread.

这篇关于NUnit(和MSTest)如何处理更改静态/共享变量的测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆