2011-03-08 16 views
5

estoy recibiendo la siguiente excepción cuando trato de ejecutar la prueba SpecFlow:NUnit, WatiN SpecFlow y STA errores de rosca

El CurrentThread necesita tener es ApartmentState establece en ApartmentState.STA ser capaz de automatizar Internet Explorer.

ya he añadido el siguiente código en App.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <sectionGroup name="NUnit"> 
     <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/> 
    </sectionGroup> 
    </configSections> 
    <NUnit> 
    <TestRunner> 
     <!-- Valid values are STA,MTA. Others ignored. --> 
     <add key="ApartmentState" value="STA" /> 
    </TestRunner> 
    </NUnit> 
</configuration> 

estoy utilizando VS 2010 y forzando mi aplicación para ejecutarse como la versión 3.5.

¡También estoy usando la pantalla GUI de la herramienta nUnit!

Respuesta

3

El siguiente código

falta.

De todos modos, cuando yo estaba usando WatiN + + Nunit MSVS, tuve esta configuración en mi proyecto de prueba:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <sectionGroup name="NUnit"> 
     <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/> 
    </sectionGroup> 
    </configSections> 
    <NUnit> 
    <TestRunner> 
     <!-- Valid values are STA,MTA. Others ignored. --> 
     <add key="ApartmentState" value="STA" /> 
    </TestRunner> 
    </NUnit> 
</configuration> 
+0

Oh sí, tengo este código por alguna razón StackOverflow no lo mostró. ¡Incluso con la configuración XML estoy obteniendo el mismo error! – azamsharp

+0

Parece que el error solo aparece cuando se ejecuta la prueba en el modo nUnit GUI. ¡Acabo de usar TestDriven.NEt y funciona como un encanto! ¡Gracias! – azamsharp

12

Si ha instalado nunit 2.5+, utilice la nueva clase en el RequiresSTAAttribute

TestFixture, RequiresSTA]

o nivel de montaje. (en Assemblyinfo.cs)

usando NUnit.Framework;

...

[assembly: RequiresSTA]

No hay necesidad de archivo de configuración. Revise este enlace para más información: http://www.nunit.org/index.php?p=requiresSTA&r=2.5