Re: Running Tests in Single Threaded Apartment

"Charlie Poole" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <004f01c873f0$ebd63b10$6401a8c0@ferrari>
Hi James, 

> I am having trouble getting NUnit to run my tests in a single 
> threaded apartment model thread.
> 
> I have a class:
> 
> <TestFixture()> _
>     Public Class FormManagerTest
> 
>         <TestFixtureSetUp()> _
>         Sub TestFixtureSetUp()
>             
> Assert.AreEqual(System.Threading.Thread.CurrentThread.GetApart
> mentState,
> System.Threading.ApartmentState.STA, _
>             "Threading Apartment State must be Set to STA for 
> COM Object to Operate Properly")
>         End Sub
> ...
> End Class
> 
> In a project UnitTests.  This unit test always fails as the 
> apartment model is set to MTA.  I have a config file 
> UnitTests.dll.config (which has Copy to Output Directory: 
> Copy Always), it exists in the same dir as nunit gui runner 
> is pointed to which from what I read should cause the tests 
> to be run in an STA thread.

If you are loading the assembly directly, your config file should
work, provided that UnitTests.dll and UnitTests.dll.config are
in the same directory. However, if you are loading a project, the
naming convention changes. If the project is named UnitTests.nunit
then the config is UnitTests.config and must be in the same directory
as the project. For a csproj or sln file, the rule is the same.

Charlie
 
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> 
>   <configSections>
>     <sectionGroup name="NUnit">
>       <section name="TestRunner"
> type="System.Configuration.NameValueSectionHandler"/>
>     </sectionGroup>
>   </configSections>
> 
>   <NUnit>
>     <TestRunner>
>       <add key="ApartmentState" value="STA" />
>     </TestRunner>
>   </NUnit>
> </configuration>
> 
> I found some references to a /thread argument for nunit.exe 
> but I think that is old as when I supply it it gives me an 
> error.  I've found a few references online but they seem to 
> be using older versions and the suggestions don't seem to work.
> 
> Any help would be appreciated.  Thank you.
> 
> James Thigpen
> JMT Systems
> 
> --------------------------------------------------------------
> -----------
> This SF.net email is sponsored by: Microsoft Defy all 
> challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Nunit-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-users
> 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.