[英]Is there a way to make Visual Studio 2010 to run all tests on the same thread?
Even when Visual Studio 2010 does not run tests in multiple parallel threads, it still uses different threads to run different test methods. 即使Visual Studio 2010不在多个并行线程中运行测试,它仍然使用不同的线程来运行不同的测试方法。 It uses one thread to run one test, and then switches to other thread to run other test.
它使用一个线程来运行一个测试,然后切换到另一个线程来运行另一个测试。 It continues switching between threads for every test method.
它会继续为每种测试方法在线程之间切换。 You can easily test it by querying thread IDs within different tests.
您可以通过查询不同测试中的线程ID轻松地对其进行测试。
I'm trying to write integration tests that initialize an actual application that uses COM objects. 我正在尝试编写集成测试,以初始化使用COM对象的实际应用程序。 Those COM objects has to be using only in STA memory model and don't have proxy/stub marshalers that can be used to call them from other thread.
这些COM对象必须仅在STA内存模型中使用,并且没有可用于从其他线程调用它们的代理/存根编组器。
An application's COM objects get initialized during the first test on the thread that was used by the first test. 在第一次测试所使用的线程上的第一次测试期间,将初始化应用程序的COM对象。 Then any call to them from other tests fails because they are calling them from different threads.
然后,其他测试对它们的任何调用都会失败,因为它们是从不同的线程进行调用。 It throws InvalidComObjectException with the "COM object that has been separated from its underlying RCW can not be used", because it cannot reach a COM object that is in other STA apartment and does not have proxy/stub marshaler.
它引发“ InvalidComObjectException”和“无法使用与其基础RCW分离的COM对象”,因为它无法到达其他STA单元中且没有代理/存根封送拆封器的COM对象。
Making Visual Studio to run all tests on the same thread will solve a problem, because all COM objects will be initialized and used on the same thread from within the same STA apartment. 使Visual Studio在同一线程上运行所有测试将解决问题,因为所有COM对象将被初始化并在同一STA单元内的同一线程上使用。
您可以尝试将NUnit用于此特定测试,因为它确实在同一线程上运行所有测试 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.