Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing NUnit-2.5 RequiresSTAAttribute with TeamCity 4
    text
    copied!<p>Using TeamCity, I'm trying to get a (TestAutomationFX) test that requires an STA thread to run .</p> <p>It works via a custom app.config that configures NUnit 2.4.x (8) (as referred to by Gishu, thanks, described at <a href="http://madcoderspeak.blogspot.com/2008/12/getting-nunit-to-go-all-sta.html" rel="nofollow noreferrer">http://madcoderspeak.blogspot.com/2008/12/getting-nunit-to-go-all-sta.html</a>)</p> <p>It works via:</p> <pre><code>/// &lt;summary&gt; /// Via Peter Provost / http://www.hedgate.net/articles/2007/01/08/instantiating-a-wpf-control-from-an-nunit-test/ /// &lt;/summary&gt; public static class CrossThreadTestRunner // To be replaced with (RequiresSTA) from NUnit 2.5 { public static void RunInSTA(Action userDelegate) { Exception lastException = null; Thread thread = new Thread(delegate() { try { userDelegate(); } catch (Exception e) { lastException = e; } }); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); if (lastException != null) ThrowExceptionPreservingStack(lastException); } [ReflectionPermission(SecurityAction.Demand)] static void ThrowExceptionPreservingStack(Exception exception) { FieldInfo remoteStackTraceString = typeof(Exception).GetField( "_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic); remoteStackTraceString.SetValue(exception, exception.StackTrace + Environment.NewLine); throw exception; } } </code></pre> <p>I'm hoping to use something built in. So NUnit 2.5.0.8322 (Beta 1)'s RequiresSTAAttribute seems ideal. It works standalone, but not via TeamCity, even when I attempt to force the issue via:</p> <pre><code>&lt;NUnit Assemblies="Test\bin\$(Configuration)\Test.exe" NUnitVersion="NUnit-2.5.0" /&gt; </code></pre> <p>The docs say the runner supports 2.5.0 alpha 4? (<a href="http://www.jetbrains.net/confluence/display/TCD4/NUnit+for+MSBuild" rel="nofollow noreferrer">http://www.jetbrains.net/confluence/display/TCD4/NUnit+for+MSBuild</a>)</p> <p>Probably answering my own question, 2.5.0 Aplha 4 doesnt have RequiresSTAAttribute, hence the runner is not honouring my Attribute...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload