Combining RequiresSTA and Timeout attributes on a test fails
Posted
by Peter Lillevold
on Stack Overflow
See other posts from Stack Overflow
or by Peter Lillevold
Published on 2010-06-10T11:42:47Z
Indexed on
2010/06/10
12:13 UTC
Read the original article
Hit count: 221
I have a test that opens and closes a WPF Window and thus requires the STA threading apartment. To safeguard the test against the window staying open (and thus hang the test indefinitely) I wanted to use the Timeout attribute.
The problem is that applying the Timeout
attribute causes the test to fail on timeout regardless of whether the test works or not. Without the attribute everything works fine.
My theory is that Timeout
causes the test to be executed on a new thread that does not inherit the STA apartment.
Is there another way to have both STA and the timeout safeguard in NUnit?
My test looks something like this:
[Test, RequiresSTA, Timeout(300)]
public void Construct()
{
var window = new WindowView();
window.Loaded += (sender, args) => window.Close();
var app = new Application();
app.Run(window);
try
{
// ...run system under test
}
finally
{
app.Shutdown();
}
}
© Stack Overflow or respective owner