Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run unit tests in STAThread mode?

Tags:

c#

nunit

sta

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 not have a main method, I don't know where/how to annotate it.

like image 548
Peter Avatar asked Mar 12 '10 16:03

Peter


People also ask

Do unit tests run in parallel C#?

Unit tests run one at a time. There is no parallelism.

How do I run unit test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.


1 Answers

If you are using nunit 2.5+, you can use the new The RequiresSTAAttribute at class

[TestFixture, RequiresSTA] 

or assembly level.

[assembly:RequiresSTA] 

No need for config file. check: http://www.nunit.org/index.php?p=requiresSTA&r=2.5

like image 60
mas_oz2k1 Avatar answered Sep 19 '22 12:09

mas_oz2k1