문제

TeamCity를 사용하여 STA 스레드를 실행 해야하는 (TestAutomationFX) 테스트를 받으려고합니다.

Nunit 2.4.x (8)를 구성하는 Custom 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)의 요구 사항이라는 것이 이상적입니다. 독립형으로 작동하지만 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는 요구 사항이 필요하지 않으므로 러너는 내 속성을 존중하지 않습니다 ...

도움이 되었습니까?

해결책

TeamCity 4.0.1에는 Nunit 2.5.0 베타 2가 포함되어 있습니다.

다른 팁

이것이 도움이되는지 알 수 있습니까? .config 파일 접근법을 통해 STA 설정 ... pre nunit 2.5에서와 같이

http://madcoderspeak.blogspot.com/2008/12/getting-nunit-to-go-all-sta.html

지금은 다음을 사용하고 있습니다.

    private void ForceSTAIfNecessary(ThreadStart threadStart)
    {
        if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            threadStart();
        else
            CrossThreadTestRunner.RunInSTA(threadStart);
    }

    [Test]
    public void TestRunApp()
    {
        ForceSTAIfNecessary(TestRunAppSTA);
    }

    public void TestRunAppSTA()
    {
        Assert.That(Thread.CurrentThread.GetApartmentState(), Is.EqualTo(ApartmentState.STA));
        ...
    }

대신에:

    [RequiresSTA]
    public void TestRunAppSTA()
    {
        Assert.That(Thread.CurrentThread.GetApartmentState(), Is.EqualTo(ApartmentState.STA));
        ...
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top