How to: Run Unit Tests in MTA mode
You might want to run your tests in MTA mode, using multithreaded apartments, because of the methods that you have used to write your tests. For example, if you use a method such as WaitHandle.WaitAll that is not supported with STA (single threaded apartment), you must run your unit tests in MTA mode. By default unit tests are run using STA.
To modify your test settings file to run your unit tests in MTA mode, follow these steps:
To run unit tests in MTA mode
To open the solution that contains the unit tests that you want to run in MTA mode, click File, point to Open, and then click Project/Solution.
The Open Project dialog box is displayed.
Select your solution, and then click Open.
To modify the test settings file, open Solution Items, right-click the test settings file, and point to Open With. Select a text or XML editor.
The file is displayed in the editor.
To set the unit tests to run in MTA mode, add the MTA mode attribute to the Execution element as shown in the following example:
<Execution> <ExecutionThread apartmentState="MTA" /> </Execution>
Save the test settings file.
Exit and restart Microsoft Visual Studio 2010.
Reload your solution and run your tests.
Your tests are displayed in the Test Results window when they run.