nunitteamcitywatinspecflowapartment-state

TeamCity SpecFlow NUnit Watin and ApartmentState STA


Im trying to get our specflow watin tests to run on our new teamcity server. The problem is that I cant get the built in nunit runner to run tests in appartmentstate STA.

We used this configuration earlier, which works with other testrunners:

<NUnit>
    <TestRunner>
        <add key="ApartmentState" value="STA" />
    </TestRunner>
</NUnit>

But the TeamCity NUnit test runner doesnt seem to pick up on this config. We have other config sanity tests in place, so we know the testrunner reads the configuration for our test project atleast.

There's the alternative to use the RequiresSTA attribute like so:

[Test, RequiresSTA]
public void ShouldRunThreadApartmentStateSTAWith()
{
  Assert.AreEqual(ApartmentState.STA, Thread.CurrentThread.GetApartmentState());
}

But since the NUnit tests are generated by SpecFlow, I don't have control over how these attributes are set.

How can I get this setup to work?


Solution

  • Found the answer.

    Setting the RequireSTA attribute in AssemblyInfo.cs makes the configuration obsolete.

    [assembly:RequiresSTA]