STA doesn't work with SpecFlow/NUnit

515 views
Skip to first unread message

bsvisser

unread,
May 26, 2011, 5:51:58 AM5/26/11
to SpecFlow
We use the following setup
* Visual Studio 2010 with .NET 4.0
* Specflow 1.6.1
* NUnit 2.5.10

We have tried configuring NUnit using STA
* Creating app.config with STA attribute
* Adding RequiresSTA to AssemblyInfo
* Adding RequiresSTA directly into the generated feature code files.

During debugging of our tests we notice that fired events are on
different threads and when using UI/WPF calls such as ShowDialog, we
get STA exceptions.

Any help would be greatly appreciated.

Bert

Gáspár Nagy

unread,
May 26, 2011, 9:22:29 AM5/26/11
to SpecFlow
Which unit test runner you use for your test? If NUnit-gui/resharper
than maybe this can be helpful:
http://houseofbilz.com/archives/2008/10/14/getting-your-nunit-tests-to-run-as-sta/

bsvisser

unread,
May 26, 2011, 11:41:06 AM5/26/11
to SpecFlow
Thanks for your reply. As stated, we are using NUnit 2.5.10. And we
did the app.config thing as suggested by your post.

The problem is for example the following code.
public void OnEnterEvent(...)
{
....
someDialog.ShowDialog()
....
}

The following happens.
* Project. Dialog is shown. When a breakpoint is placed, the code is
executed on the main thread.
* Specflow test project. STA exception. When a breakpoint is placed,
the code is executed on a random new thread (hence the conclusion that
the project is not in STA but MTA)



On May 26, 3:22 pm, Gáspár Nagy <gaspar.n...@gmail.com> wrote:
> Which unit test runner you use for your test? If NUnit-gui/resharper
> than maybe this can be helpful:http://houseofbilz.com/archives/2008/10/14/getting-your-nunit-tests-t...

Andrew Siemer

unread,
May 28, 2011, 11:23:30 AM5/28/11
to spec...@googlegroups.com, SpecFlow
To get this to work I had to put the attribute directly on the generated unit test. The config didn't seem to work.

Andrew Siemer

Reply all
Reply to author
Forward
0 new messages