Do the SetUp and TearDown methods need [RequiresSTA] if tests have it?

不想你离开。 提交于 2019-12-12 10:49:30

问题


I can run my WatiN tests with ReSharper without issues. Each test has the RequiresSTA attribute and runs fine.

When I try run all the tests in the class (TestFixture) I get the following error:

One or more child tests had errors
Exception doesn't have a stacktrace
<testname>  ignored: Invalid signature for SetUp or TearDown method: TestSetup
<testname>  ignored: Invalid signature for SetUp or TearDown method: TestSetup
<testname>  ignored: Invalid signature for SetUp or TearDown method: TestSetup

The error doesn't indicate what I need to change to make it work.

If I then select all the tests that have been ignored in the Unit Test Sessions window, I can run them without problems.

What must I change to allow me to run all the tests in the TestFixture?


回答1:


I have met the same problem. I changed SetUp() and TearDown() methods to be public, then it worked.




回答2:


I've always set the apartment state in the App.config file of my solution and the NUnit GUI runner runs entire fixtures as expected.

App.config starts off like this.

<?xml version="1.0"?>
<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>
  <appSettings>
........

Edit: I'm using Watin2.1 and NUnit 2.5.



来源:https://stackoverflow.com/questions/17587433/do-the-setup-and-teardown-methods-need-requiressta-if-tests-have-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!