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

查看:17
本文介绍了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 或 via 中运行时并行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天全站免登陆