如何测试一个WPF用户界面? [英] How to test a WPF user interface?

查看:429
本文介绍了如何测试一个WPF用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用共赢的形式与 MVC /的 MVP 架构,我通常会使用一个类来包装一个视图,而用嘲笑的模型和控制器/ presenter测试用户界面。包装类将通过属性和事件使得大多数都在用户界面中可观察性的测试运行。

Using win forms with an MVC/MVP architecture, I would normally use a class to wrap a view to test the UI while using mocks for the model and controller/presenter. The wrapper class would make most everything in the UI an observable property for the test runner through properties and events.

这将是一个可行的方法来测试一个WPF应用程序?有没有更好的办法?是否有任何陷阱需要提防?

Would this be a viable approach to testing a WPF app? Is there a better way? Are there any gotchas to watch out for?

推荐答案

对于测试本身,你可能最好关闭使用的 UI自动化框架。或者,如果你想要一个更流畅的使用框架和WPF /的WinForms / win32 /下SWT无关的方式,你可以下载的从codePLEX白(前提是你在一个位置,使用开源$ C ​​$ C在您的环境)。

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).

有关的陷阱;如果你想进行单元测试你的观点,你可能会到一些线程运行问题研究。举例来说,如果你正在运行的NUnit默认的TestRunner会在MTA(多线程公寓)运行,同时为WPF需要为STA中运行(单线程公寓)。 迈克两个有一个真正的轻松入门,开始单元测试WPF,但没有考虑线程问题。约什 - 史密斯在对线程问题的几点思考这篇文章,他也指出了的由克里斯Hedgate这篇文章。克里斯使用的彼得教务长的修改版<一个href="http://www.peterprovost.org/blog/post/NUnit-and-Multithreaded-Tests-CrossThreadTestRunner.aspx"相对=nofollow> CrossThreadTestRunner 包装在更友好一点的方式MTA / STA的问题。

For the gotchas; If you're trying to unit 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.

这篇关于如何测试一个WPF用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆