Search code examples
nunitnantwatin

nunit2 task , NAnt , Watin - ApartmentState STA error


I am exploring WatIN automation framework driven by NUnit and Nant. I have Apartmentstate set in App.config

<NUnit>
    <TestRunner>
      <!-- WatiN can only host IE in STA mode -->
      <add key="ApartmentState" value="STA"/>
    </TestRunner>
</NUnit>

I have also set [TestFixture, RequiresSTA] in test class. This works perfectly fine when i use nunit-console testrunner or Nunit GUI runner.

Using Nunit2 runner in NAnt throws this exception

[nunit2] : [DEBUG] The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer

How do I workaround this issue?

Thanks Jenga


Solution

  • I had a similar problem. I was able to fix it by adding the /nothread arg when calling nunit-console.exe from my nant target.

    Example:

    <exec verbose="true" 
        workingdir="${project::get-base-directory()}\build"
        program="tools\nunit\nunit-console.exe" basedir="${project::get-base-directory()}">
    
        <arg value="${ua-testproject.name}" />
        <arg value="/nothread" />
        <arg value="/xml:${ua-tests.report}" />
    </exec>