Question

Comment définissez-vous l'état de l'appartement dans le canal GUI NUnit? Je suis en train d'exécuter un seul test NUnit avec Watin et je reçois le message:

  

MyNamespace.LoginTests.CanLogin:
  System.Threading.ThreadStateException: Le CurrentThread doit avoir son ApartmentState réglé sur ApartmentState.STA pour être en mesure d'automatiser Internet Explorer

.
Était-ce utile?

La solution

Vous devez ajouter une configuration au fichier app.config de votre assemblée (si vous ne disposez pas d'une fois, de créer un nouveau) pour dire NUnit de fonctionner comme STA:

<?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>

( originale la source )

Autres conseils

A partir de NUnit 2.5, utilisez RequiresSTA attribut dans vos tests.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top