tags:

views:

263

answers:

1

When I try to run a WatIn test trough the NUnit ide, I get the error message:

ConsoleApplication1.Tests.CanBrowseToMicrosoft: System.Threading.ThreadStateException : The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.

I created an application configuration file called ConsoleApplication1.exe.config which is below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    <sectionGroup name="NUnit">
    <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
</configSections>

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

My class Tests.cs is below:

[TestFixture]
public class Tests
{
    [Test]
    public void CanBrowseToMicrosoft()
    {
        using (var browser = new IE())
        {
            browser.GoTo("http://www.microsoft.com/");
            Assert.That("Microsoft Corporation", Is.EqualTo(browser.Title));
        }
    }
}

Am I doing something wrong?

The other question I had was how do I get the NUnit test results to show up in vs2008 ide instead of having to run the NUnit Gui?

+1  A: 

I figured it out, because I was loading an NUnit project called Tests.nunit, I need to call the application configuration file Tests.config. After this change, it worked fine.

Xaisoft