注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

还东国的博客

行之苟有恒,久久自芬芳

 
 
 

日志

 
 

TDD测试  

2016-10-12 14:06:20|  分类: 基本知识 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

TDD测试

 

做为国内软件开发者,其实也不容易,国外的东西刚刚进来,还没有学熟悉,国外的大牛们就开骂,说这个不好,那个也不好,然后有更牛的人推出更牛的东西。可怜的国内程序员们,疲于奔命。

比如现在的TDD测试,国内好推崇的样子,结果大牛们开撕了。

以下转自:http://www.zhihu.com/question/37623307/answer/72979064

 

大神语录

以下来自 BeckFowlerHansson 三人对话。

为什么要质疑 TDD

David said he started this discussion because people wouldn't talk about cases where TDD wasn't effective. They weren't feeling good or confident, but were told they must use TDD. He wants to open the sphere of acceptable reactions so we can discuss when TDD is and isn't appropriate. Lots of people on the internet talk about how good TDD is, but people were afraid to say it wasn't working for them.

 

大赞 DHH 的勇气!DHH 在美国所看到的,与我过去十多年在中国所看到的差不多,这些现象是运动式传播、宗教式宣传、业绩驱动的商业营销(只许说好,不许说坏),综合运用带来的效果。

TDD 的问题

David opened the discussion by raising his three major issues with TDD and Unit Testing: confusion over the definition of TDD and unit testing, test-induced damage through using mocks to drive architecture, and how the red/green/refactor cycle of TDD never worked for him.

TDD 的本质

I (Martin Fowler) commented that when we first worked together at C3, we didn't start using TDD, but ensured each programming episode delivered code and tests together. Kent said that programmers deserve to feel confident that their code works, TDD is one (not the only) way to reach that.

好吧,Kent 说了 TDD 只是一个选项,不是唯一。

But in response to David's question about mocks, he (Kent Beck) said he rarely uses them, he's concerned that those that do often find refactoring difficult, while he finds testing makes refactoring easier.

TDD 之父居然基本不用 Mock

DHH Mock 的意见一直是很大的:

David said his reaction was to seeing people describe TDD in a mock-heavy style as a moral thing to do and the result was a lot of code that was poorly designed due to its desire to enable isolated unit tests.

TDD 在西方实践的一个典型现象,大量使用、依赖于 Mock 竟然上升到了道德的高度。大家回忆一下,2010 年以前 XP 在中国的实践是否也有类似的现象和趋势。不只是中国人爱跟风啊。

有一个例外。您是否还记得, @张恂老师 多年前曾建议过让大家少用 Mock

对此,Fowler 进行了澄清(撇清 heavy mocking TDD 的关系):

I comment that there are two problems with terminology where different things get conflated: first that DHH's critique of TDD was based on an assumption that you had to use heavy mocking in TDD, which isn't the case; second that there is a difference between self-testing code and TDD. TDD is one way to achieve self-testing code.

TDD 实践是否存在 over testing(过度测试)的现象?

The first issue he (David Hansson) wanted to raise was over-testing. It's often said you shouldn't write a line of code without a failing test, at first this seems reasonable but it can lead to over-testing, such as where there are four lines of test code for every line of production code. This means that when you need to change behavior, you have more code to change.

TDD 是否破坏了(架构)设计?

TDD 的适用性

TDD 的价值

David said his experience was similar. His introduction to testing was through TDD, he liked it and tried to apply it to everything but slowly realized that lots of areas in an MVC web application didn't feel good for TDD. This doesn't mean TDD isn't effective for some situations, just that those cases are a small percentage of his work. But abandoning TDD doesn't mean he wants to give up self-testing code - that's always been the value of TDD to him.

TDD QA

敏捷的现状

I (Martin Fowler) disagree that agile has won - the label has won, but many people say they do agile but don't really. This is typical for things like this, a process I call semantic diffusion. The big win is that now we are able to do agile openly at clients.

结论

He (Kent Beck) comes out firmly contradicting David: TDD isn't dead, but is glad David set fire to it so it could come out like a phoenix.

特别是上面提到的Mock,刚刚使用的时候儿觉得就是大杀器。真得假得都可以测试,弄得IO操作啥的都可以虚拟出来,我勒个去。这刚刚理解了这个精神,现在老大和牛人们就这样说,叫人情何以堪。

说实话,对测试的重视程序还是重视不够,所以对这方面的学习和研究投入的非常少。以后看来还是得要认真得多看大老外的东西。师夷人之技以制夷。

 

 

 

 

 

  评论这张
 
阅读(27)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017