I am working on unit testing and I have to pass context of one thread to other one. In real life the first one would be UI thread and all will be ok (I hope). But my unit test has not UI (it is some testing thread).
I have read: “One thread that always has a SynchronizationContext is the UI thread.”
Is it possible to attach context of one thread (Non UI) to other one? How to do that?
I am working on unit testing and I have to pass context of one
Share
I think you might need to rethink your testing strategy.
If you really want to test interaction between GUI and some background task Thread safety wise, you can create simple WinForm and try it out.
Or try to create test so that your GUI form is behaving as expected after you get some results from your back thread (i.e. displaying it correctly).
Creating unit tests for GUIs are quite tricky. That’s why people tend to remove all the business and any other logic outside GUI so that it can be easily testable.
maybe you can consider using WPF with MVVM, or WinForms with MVP, which makes it easier to draw that line