开发者

Is there a way to make Visual Studio 2010 to run all tests on the same thread?

开发者 https://www.devze.com 2023-04-10 22:26 出处:网络
Even when Visual Studio 2010 does not run tests in multiple parallel threads, it still uses different threads to run different test methods. It uses one thread to run one test, and then switches to ot

Even when Visual Studio 2010 does not run tests in multiple parallel threads, it still uses different threads to run different test methods. It uses one thread to run one test, and then switches to other thread to run other t开发者_开发问答est. It continues switching between threads for every test method. You can easily test it by querying thread IDs within different tests.

I’m trying to write integration tests that initialize an actual application that uses COM objects. 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.

An application's COM objects get initialized during the first test on the thread that was used by the first test. 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.

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.


You could try using NUnit for this specific test, as it does run all tests on the same thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号