How Does TDD Affect Design?
来源:互联网 发布:redhat linux centos 编辑:程序博客网 时间:2024/06/05 15:57
转自http://www.jamesshore.com/Blog/How-Does-TDD-Affect-Design.html
How Does TDD Affect Design?
17 May, 2014
(This essay was originally posted to the Let's Code JavaScript blog.)
I've heard people say TDD automatically creates good designs. More recently, I've heard David Hansson say it creates design damage. Who's right?
Neither. TDD doesn't create design. You do.
TDD Can Lead to Better Design
There are a few ways I've seen TDD lead to better design:
A good test suite allows you to refactor, which allows you to improve your design over time.
The TDD cycle is very detail-oriented and requires you to make some design decisions when writing tests, rather than when writing production code. I find this helps me think about design issues more deeply.
TDD makes some design problems more obvious.
None of these force you to create better design, but if you're working hard to create good design, I find that these things make it easier to get there.
TDD Can Lead to Worse Design
There are a few ways I've seen TDD lead to worse design:
TDD works best with fast tests and rapid feedback. In search of speed, some people use mocks in a way that locks their production code in place. Ironically, this makes refactoring very difficult, which prevents designs from being improved.
Also in search of speed, some people make very elaborate dependency-injection tools and structures, as well as unnecessary interfaces or classes, just so they can mock out dependencies for testing. This leads to overly complex, hard to understand code.
TDD activates people's desire to get a "high score" by having a lot of tests. This can push people to write worthless or silly tests, or use multiple tests where a single test would do.
None of these are required by TDD, but they're still common. The first two are obvious solutions to the sorts of design problems TDD exposes.
They're also very poor solutions, and you can (and should) choose not to do these things. It is possible to create fast tests and rapid feedback without these mistakes, and you can see us take that approach in the screencast.
So Do Your Job
TDD doesn't create good design. You do. TDD can help expose design smells. You have to pay attention and fix them. TDD can push you toward facile solutions. You have to be careful not to make your design worse just to make testing better.
So pay attention. Think about design. And if TDD is pushing you in a direction that makes your code worse, stop. Take a walk. Talk to a colleague. And look for a better way.
- How Does TDD Affect Design?
- How does reszing a image affect the intrinsic camera matrix?
- 4KB Alignment: How does it affect the efficiency of a hard disk
- Does #include affect program size?
- Does it affect work or family
- How will XML affect my document links?
- Oracle Tip: Understand how NULLs affect IN and EXISTS
- How will the new iPhone screen sizes affect iOS developers?
- How New Types of DDoS Affect the Cloud
- How does netstat work
- How Does it End()?
- How does XVCL work?
- How does JNA work?
- How does cas work
- how does wifi work?
- How MySQL Does Sorting
- how does RemoteFX works?
- How does google work
- Unsupported major.minor version 51.0解决
- mac xcode5.1 安装 ruby rails 遇到的问题
- ubuntu问题
- Linux新手学习笔记3
- 如何把图片上的文字转换成word的文字。
- How Does TDD Affect Design?
- 什么样的外链最有效
- 用Java写的Json服务,源代码清单
- C++的构造函数
- 练习 6.22
- uva 10497 - Sweet Child Makes Trouble(dp+高精度)
- Java开发FTP功能的apache工具包,小心使用为妙
- 【不明觉厉,厚积薄发】ARM_linux(十一)
- [2014.5.22][UBUNTU]Ubuntu与Windows系统时间不同步的问题