How to test a WPF user interface?

As for the testing itself, you’re probably best off using the UI Automation framework. Or if you want a more fluent and wpf/winforms/win32/swt-independent way of using the framework, you could download White from Codeplex (provided that you’re in a position to use open source code in your environment).

For the gotchas; If you’re trying to test your views, you will probably run in to some threading issues. For instance, if you’re running NUnit the default testrunner will run in MTA (Multi-Threaded Appartment), while as WPF needs to run as STA (Single-threaded Appartment). Mike Two has a real easy getting-started on unit testing WPF, but without considering the threading issue. Josh Smith has some thoughts on the threading issue in this post, and he also points to this article by Chris Hedgate. Chris uses a modified version of Peter Provost’s CrossThreadTestRunner to wrap the MTA/STA issues in a bit more friendly way.

Leave a Comment