1
votes

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?

2

2 Answers

1
votes

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.

1
votes

There is a cleaner way to resolve your issue with STAThread requirement, but it requires NUnit 2.5.

Also, have you tried TestDriven.Net to run unit tests from Visual Studio?