TeamCity を使用して、STA スレッドを実行する必要がある (TestAutomationFX) テストを取得しようとしています。
これは、NUnit 2.4.x (8) を構成するカスタム app.config を介して機能します (Gishu による参照、ありがとう、http://madcoderspeak.blogspot.com/2008/12/getting-nunit-to-go- で説明) 。 all-sta.html )
次の方法で機能します。
/// <summary>
/// Via Peter Provost / http://www.hedgate.net/articles/2007/01/08/instantiating-a-wpf-control-from-an-nunit-test/
/// </summary>
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;
}
}
組み込みのものを使用したいと思っています。したがって、NUnit 2.5.0.8322 (ベータ 1) の RequiresSTAAttribute が理想的です。スタンドアロンで動作しますが、TeamCity 経由では機能しません。次の方法で問題を強制しようとしてもです。
<NUnit Assemblies="Test\bin\$(Configuration)\Test.exe" NUnitVersion="NUnit-2.5.0" />
ドキュメントによると、ランナーは 2.5.0 alpha 4 をサポートしていますか? ( http://www.jetbrains.net/confluence/display/TCD4/NUnit+for+MSBuild )
おそらく私自身の質問に答えて、2.5.0 Aplha 4 には RequiresSTAAttribute がないため、ランナーは私の属性を尊重していません...