Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing UI Thread in nunit

Tags:

nunit

I am trying to write a test case where I have to access UI Thread. Does Nunit provide a way to access the ui thread or is there anyway I can execute some code on UI Thread in my test case. Thanks

Update: I'm using winform. The usual way is to have the presentation layer and write the test cases against it but in this situation I have a grid that I need to work with and to populate it, its DataSource property needs to be set on UI Thread.

like image 415
Sheraz Avatar asked Jan 24 '23 12:01

Sheraz


1 Answers

That very much depends on which technology you are using for your UI. Depending on that it might be possible to setup the NUnit runner thread to act as your UI thread.

Genrally though, it is recommended to make the actual UI layer as thin as possible to reduce the amount of UI-code to test.


If you really need to have a live WinForms control on your NUnit thread, consider using Application.DoEvents() which will handle all currently pending events in the message queue. Be aware that doing so might bring you other problems though.

like image 168
David Schmitt Avatar answered Jan 31 '23 22:01

David Schmitt