在开发 UI 时 TDD 是否适用? [英] Does TDD apply well when developing an UI?

查看:23
本文介绍了在开发 UI 时 TDD 是否适用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您对在开发用户界面时使用 TDD 有何看法和经验?

What are your opinions and experiences regarding using TDD when developing an user interface?

这个问题我已经思考了一段时间,但无法做出最终决定.我们即将开始一个 Silverlight 项目,我检查了 Microsoft Silverlight 单元测试框架考虑到 TDD,但我不确定如何将这种方法应用于一般的 UI 开发 - 或者特别是 Silverlight.

I have been pondering about this question for some time now and just can't reach a final decision. We are about to start a Silverlight project, and I checked out the Microsoft Silverlight Unit Test Framework with TDD in mind, but I am not sure how to apply the approach to UI-development in general - or to Silverlight in particular.

问题是使用 TDD 进行 UI 开发是否实用,而不是如何进行关注点分离.

The question is about if it is practical thing to use TDD for UI-development, not about how to do separation of concerns.

推荐答案

尝试测试 UI 组件的确切位置毫无意义.首先是因为布局是主观的,应该由人类测试".其次,因为随着 UI 的变化,您将不断地重写测试.

Trying to test the exact placement of UI components is pointless. First because layout is subjective and should be "tested" by humans. Second, because as the UI changes you'll be constantly rewriting your tests.

同样,不要测试 GUI 组件本身,除非您正在编写新组件.信任框架来完成它的工作.

Similarly, don't test the GUI components themselves, unless you're writing new components. Trust the framework to do its job.

相反,您应该测试构成这些组件的行为:构成应用程序的控制器和模型.在这种情况下使用 TDD 会促使您实现关注点分离,因此您的模型真正是一个数据管理对象,而您的控制器实际上是一个行为对象,并且它们都没有与 UI 紧密耦合.

Instead, you should be testing the behavior that underlies those components: the controllers and models that make up your application. Using TDD in this case drives you toward a separation of concerns, so that your model is truly a data management object and your controller is truly a behavior object, and neither of them are tightly coupled to the UI.

这篇关于在开发 UI 时 TDD 是否适用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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