Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
10 votes
3 answers
4k views

How to run NUnit test in STA thread?

We are in the process of porting a WPF app to .NET Core 3, preview 5. Some NUnit tests need to run in STA threads. How can this be done? None of the attributes like [STAThread], [RequiresSTA], ... ...
Sven's user avatar
  • 185
4 votes
2 answers
2k views

NUnit async test + RequiresSTA => await not returning on STA thread

The below code: [RequiresSTA] [Test] public async Task TestSta() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId+" - "+Thread.CurrentThread.GetApartmentState()); ...
Olivier's user avatar
  • 5,688
4 votes
1 answer
1k views

Unable to set WinForms clipboard in unit test

I'd like to populate the Forms.Clipboard with text from a NUnit test. The first problem I encountered was that the Clipboard must be used in STA mode. I found the solution (NUnit 2.5.x+) to set the ...
Torbjörn Kalin's user avatar
62 votes
4 answers
31k views

How to run unit tests in STAThread mode?

I would like to test an app that uses the Clipboard (WindowsForms) and I need the Clipboard in my unit tests also. In order to use it, it should run in STA mode, but since the NUnit TestFixture does ...
Peter's user avatar
  • 48.9k