Windows窗体的Visual Studio单元测试 [英] Visual Studio Unit Testing of Windows Forms

查看:112
本文介绍了Windows窗体的Visual Studio单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在Visual Studio 2008中的一个项目上工作。我们正在使用随其提供的内置测试套件(Microsoft.VisualStudio.TestTools.UnitTesting命名空间)。事实证明,令我们非常恼火的是,大量的复杂性(以及因此而来的错误)已被编码到我们的UI层中。虽然我们的单元测试在覆盖我们的业务层方面做得不错,但是我们的UI层却是一个持续不断的困扰。理想情况下,我们也想对其进行单元测试。有谁知道在Visual Studio中实现与Microsoft兼容的好方法吗?会不会在将 nUnitForms 之类的单元测试框架与Microsoft东西混合时带来某种冲突?在单元测试表单中,我应该注意哪些明显的陷阱?

We're working on a project here in Visual Studio 2008. We're using the built-in testing suite provided with it (the Microsoft.VisualStudio.TestTools.UnitTesting namespace). It turns out, that much to our chagrin, a great deal of complexity (and therefore errors) have wound up coded into our UI layer. While our unit tests do a decent job of covering our business layer, our UI layer is a constant source of irritation. We'd ideally like to unit-test that, as well. Does anyone know of a good "Microsoft-compatible" way of doing that in visual studio? Will it introduce some sort of conflict to 'mix' unit testing frameworks like nUnitForms with the Microsoft stuff? Are there any obvious bear traps I should be aware of with unit-testing forms?

推荐答案

您需要重构UI,以便该用户界面不需要任何单元测试。 UI应该包含最少或没有业务逻辑。有许多模式可以解决此问题。马丁·福勒(Martin Fowler)的一篇很好的文章很好地解释了这些模式: http://martinfowler.com/eaaDev/ uiArchs.html

You would need to refactor the UI so that UI does not need any unit testing. UI should contain minimum or no business logic. There are many patterns that deal with this issue. Martin Fowler has a very good article that explains a lot about these patterns: http://martinfowler.com/eaaDev/uiArchs.html

Martin Fowler的Refactoring书中有一小章谈到了重构不可测试的UI。您还可以阅读有效地使用旧版代码。

There is a small chapter in the Refactoring book by Martin Fowler that talks about refactoring the non testable UI. You could also read Working Effectively With Legacy Code.

注意:有些工具可用于自动执行UI测试。 SilkTest浮现在我的脑海。但是如果可能的话,我不会使用它们。

Note: There are tool that could be used to automate the UI testing. SilkTest comes to my mind. But I would not use them if possible.

这篇关于Windows窗体的Visual Studio单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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