I cannot find a way to do this for MSTest in Visual Studio 2015. How do you specify the apartment state to be MTA for all running tests?
Asked
Active
Viewed 533 times
0
-
Does this answer your question? https://stackoverflow.com/questions/4730498/mstest-setting-apartment-threading-to-mta – Alexander Pacha Sep 08 '16 at 10:56
-
@alexander-pacha: not really because that is not for 2015. There does not seem to be an easy way of getting a .testsettings file in 2015. I would obviously prefer a way that uses the .runsettings file. – Asher Sep 08 '16 at 12:15
-
1But there is a way to get a TestSettings file. In the solution explorer right click on a project, then `Add... -> New Item... -> Test Settings / Test Settings`. And this file can be used in the menu: `Test -> Test Settings -> Select Test Settings File` – Alexander Pacha Sep 08 '16 at 12:39
-
! I was trying to add to the Project not the solution. Thanks that should help me get going. – Asher Sep 09 '16 at 07:12
1 Answers
1
As per the comment above in the OP's question, you first need to add a test settings file.
In the solution explorer right click on a project, then Add... -> New Item... -> Test Settings / Test Settings. And this file can be used in the menu: Test -> Test Settings -> Select Test Settings File
Open this file using a text editor and add / edit the following value
<Execution>
<ExecutionThread apartmentState="MTA" />
</Execution>
Your test settings file should now look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings
id="ba23bf15-d0c7-48fc-b300-6f04c3fbe665"
name="TestSettings1"
enableDefaultDataCollectors="false"
xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description><!--_locID_text="Description1"-->These are default test settings for a local test run.</Description>
<Deployment enabled="false" />
<Execution>
<ExecutionThread apartmentState="MTA" />
</Execution>
</TestSettings>
Finally, restart Visual Studio.

James Westgate
- 11,306
- 8
- 61
- 68