ASP.NET - 你怎么单元测试器WebControls? [英] ASP.NET - How do you Unit Test WebControls?

查看:125
本文介绍了ASP.NET - 你怎么单元测试器WebControls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧。

所以我想它的时候,我到单元测试,因为大家都在敲打它足够长的时间。我已经安装了NUnit的,通过一些介绍到单元测试式的教程了。

So I figure it's about time I get into unit testing, since everyone's been banging on about it for long enough. I've installed NUnit and gone through a few "intro to unit testing" type tutorials.

我目前正在组建一个小型的框架,以帮助重建我们的Web应用程序之一,所以我创建了一个VS2008项目我的框架,我想单元测试它,因为我走了。

I'm currently putting together a small framework to help with the rebuild of one of our web apps, so I've created a VS2008 project for my framework and I want to unit test it as I go.

在地球上我怎么去单元测试器WebControls?这些方法都是受保护或私有,并且由于它是一个框架,也没有多少人,但器WebControls。

How on earth do I go about unit testing the WebControls? The methods are all protected or private, and since it's a framework, there isn't much else but WebControls.

任何指针?

烧伤

推荐答案

您可以做的模型 - 视图 - 控制器或模型 - 视图 - presenter型架构,而无需使用一个完全成熟的框架。你已经发现了单元测试的UI组件是困难的。有周围的方式,但你可能不希望走这条路。通常这会令你的测试很难维持,更多的维护噩梦的东西程序员也离不开谁: - )

You can do model-view-controller or model-view-presenter type architectures without using a full blown framework. You already found out that unit-testing ui-components is difficult. There are ways around that but you probably don't want to go that route. Usually this will make your tests very hard to maintain, more maintenance nightmare's is something programmers can do without :-)

尝试分离出来你要测试的功能,在控制或presenter级。然后测试类。为了让更多的可测试性,你可以隐藏控件类(视图)的接口后面,使控制器或presenter谈话通过接口视图。这样,你可以嘲笑了查看您的测试。

Try to separate out the functionality you want to test in a "controller" or "presenter" class. Then test that class. To make it more testable you can hide the usercontrol class (the view) behind an interface and make the controller or presenter talk to the view through the interface. That way you can mock up the view in your tests.

我知道这听起​​来像一个大量的工作,这似乎是一个解决办法,但如果你习惯了这个它是一个很好的真的架构,使得它更容易改变UI行为。您可以随时开始使用一个真实的MVC框架,当你真的需要它: - )

I know this sounds like a lot of work and it seems like a workaround but if you get used to this it's a realy nice architecture that makes it far easier to change ui behaviour. You can always start using a "real" mvc framework when you realy need it :-)

这篇关于ASP.NET - 你怎么单元测试器WebControls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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