强制MSTest使用单个线程 [英] Forcing MSTest to use a single thread
问题描述
给出此测试装置:
[TestClass]
public class MSTestThreads
{
[TestMethod]
public void Test1()
{
Trace.WriteLine(Thread.CurrentThread.ManagedThreadId);
}
[TestMethod]
public void Test2()
{
Trace.WriteLine(Thread.CurrentThread.ManagedThreadId);
}
}
通过Visual Studio或命令行在MSTest上运行测试将打印两个不同的线程号(但它们仍然按顺序运行).
Running the test with MSTest through Visual Studio or command line prints two different thread numbers (yet they are run sequentially anyway).
是否有一种方法可以强制MSTest使用单个线程运行它们?
Is there a way to force MSTest to run them using a single thread?
推荐答案
为了使MSTest在大量使用nHibernate的大型项目上以单线程模式运行,我花了无尽的时间. (不是问题,不是)ISession
.
I've fought for endless hours to make MSTest run in a single threaded mode on a large project that made heavy use of nHibernate and it's not-thread-safe (not a problem, it's just not) ISession
.
我们花了更多时间编写代码来支持MSTest的多线程性质,因为-就我和我的团队所知-无法在单线程模式下运行MSTest.
We ended up more time writing code to support the multi-threaded nature of MSTest because - to the best of my and my teams knowledge - it is not possible to run MSTest in a single threaded mode.
这篇关于强制MSTest使用单个线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!