简体   繁体   English

有没有一种方法可以使Visual Studio 2010在同一线程上运行所有测试?

[英]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.

相关问题 如何在 Visual Studio Code 中运行所有测试 - How to run all tests in Visual Studio Code Visual Studio 2010中的单元测试 - Unit Tests in Visual Studio 2010 <Not Available>和Visual Studio 2010的“线程”窗口中的[Thread Destroyed]详细信息 - <Not Available> and [Thread Destroyed] details in Thread window for Visual Studio 2010 Visual Studio 2010代码分析 - 在解决方案上运行 - Visual Studio 2010 Code Analysis - Run on Solution 如何使用.NET代码以自动化方式运行Microsoft Visual Studio单元测试? - How can I run Microsoft Visual Studio Units Tests in an automated way using .NET code? 在Visual Studio单元测试(MSTest)中对项目中的所有测试进行每次测试之前,是否可以执行初始化代码? - Is there a way to execute initializer code before each test in Visual Studio Unit Testing (MSTest) for all tests in a project? 如何从jenkins运行Visual Studio 2010测试项目? - How to run Visual studio 2010 Test Project from jenkins? 选择要在 Visual Studio 2010 中调试或运行的解决方案下的项目 - Selecting which project under a solution to debug or run in Visual Studio 2010 我可以从闪存驱动器运行Visual Studio 2010吗? - Can I run Visual Studio 2010 from a flash drive? Visual Studio 2010中的/ LinkResource - /LinkResource in Visual Studio 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM