Welcome to MSDN Blogs Sign in | Join | Help

SYSK 365: How to get your unit tests (test project in Visual Studio 2008, a.k.a. MSTest) run multithreaded

If you want to test code that requires an MTA threading model (e.g. the code being tested uses WaitHandle.WaitAll), you need to change the .testrunconfig file manually and change the threading model from STA to MTA.

 

There are other posts that say for VS 2005, you add the following line to the config file:

<apartmentState type="System.Threading.ApartmentState">

<value__ type="System.Int32">1</value__>

</apartmentState>

 

Unfortunately, same posts say that in VS 2008 you use

<ExecutionThread apartmentState="1" />

 

In my experience, it doesn’t work!  Instead, you should use

          <TestRunConfiguration ...>

            ...

<ExecutionThread apartmentState="MTA" />

</TestRunConfiguration>

 

 

To check the threading model used, add the following line to your test(s):

 

[TestMethod]

public void YourTest()

{

System.Diagnostics.Debug.WriteLine(System.Threading.Thread.CurrentThread.GetApartmentState().ToString());

 

// TODO: Add test logic here

}

 

 

 

 

Published Friday, February 22, 2008 9:47 AM by irenak

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# SYSK 365: How to get your unit tests (test project in Visual Studio 2008, a.k.a. MSTest) run multithreaded

Friday, February 22, 2008 1:08 PM by Noticias externas

If you want to test code that requires an MTA threading model (e.g. the code being tested uses WaitHandle

# LitwareHR on SSDS - Part V - Searching across Containers

In SQL Server Data Services, the scope of a query is bound to a Container , but in LitwareHR we had a

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker