单元测试要走多远? [英] How far to go with unit testing?

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

问题描述



我有一个关于找到单元测试的最佳平衡的问题.在一个示例中,我有一个网站,该网站使用其数据服务.如果我分解解决方案,则可以分为以下几层:

服务
数据访问层
业务逻辑层
服务API层
网站
服务客户端层
应用程序数据管理器层
表单模型层

我可以只为表单模型层和服务api层编写单元测试,这将提供100%的代码覆盖率,并确定应用程序和服务之间的重大更改.你们大多数人是否认为这足以满足需要或针对所有层进行单元测试?

Hi,

I have a question about finding the best balance of unit testing. I have in one example a website which consumes a services for its data. If I break the solution down I have the following layers:

Service
Data Access Layer
Business Logic Layer
Service API Layer
Website
Service Client Layer
Application Data Manager Layer
Form Model Layer

I could write unit tests for just the form model layer and the service api layer which would give 100% code coverage and would identify breaking changes between the application and the service. Do most of you think that would be sufficient or would there be merit developing unit tests for all of the layers?

推荐答案

没有人能告诉您确切的答案.实际上,这取决于您的项目的更多细节.我希望我不必证明测试不能证明任何东西?更准确地说,您可以证明存在缺陷,但是否则,如果测试没有发现缺陷,则无论您进行多少测试,都无法证明所有缺陷都已修复.因此,应根据项目的逻辑分析,性质,架构和设计来确定测试主题的数量和集合.并且该决定应基于大量常识.

现在,我要指出的是,这些层并不是真正的单元,除非您的项目很小.在相当大和/或复杂的项目中,单位应小得多.应该在一些较大的团队协作下,以最小的细粒度级别对单元进行测试.同样,这取决于您的设计.不仅如此相反,您设计的所有内容都应包括并考虑到测试,并促进单元和协作的可测试性".

最后,我不建议跳过测试的任何层.同样,这取决于您的项目,尤其取决于您可以负担的资源.

最后,一篇不是100%相关但非常有趣且有些相关的文章:
Joel Spolsky,没有测试人员的前五(错误)原因
http://www.joelonsoftware.com/articles/fog0000000067.html [
No one can tell you the exact answer. It really depends on your project in further detail. I hope I don''t have to proof that testing cannot proof anything? More exactly, you can proof there is a defect, but otherwise, if testing finds no defects, it cannot proof that all defects are fixed, no matter how much you test. So, the amount and set of subjects for testing should be made dependent on some logical analysis, nature, architecture and design of your project; and the decision should be based on a good amount of common sense.

Now, I would note that the layers are not really units, unless your project is really small. In a considerably big and/or complex project the units should be much smaller. The units should be tested on the minimal fine-grain level, in some bigger groups in collaboration. Again, it depends on your design; but not just this; rather, all you design should include and take into account the testing and promote the "testability" of the units and collaboration.

Finally, I would not advise to skip any layers from testing. Again, it depends on your project, in particular, on the resources you can afford.

And, to finish with that, one not 100% relevant, but very interesting and somewhat related article:
Joel Spolsky, Top Five (Wrong) Reasons You Don''t Have Testers,
http://www.joelonsoftware.com/articles/fog0000000067.html[^].

—SA


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

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