TDD Tips

How to design the testable software? You may always find some best practices about designing for scalable, extensible or maintainable. To be testable, the best way should be TDD. Followings are some tips from my real practices on TDD.

1 TDD is design process; it let you design for testing, naturally

Write the test firstly, it does not only help you find the bugs; but the most important point is to let you design for test naturally.

Also you should keep in mind, tests not only help you find bugs, but also protect your codes; when some changes impact on your existing codes, the tests will be broken.

 

2 Keep the implementation simple

Keep your implementation simple, just let the test pass. The complex implementation may introduce the logics or codes not covered by the tests, even leads some codes not testable.

 

3 TDD in each scope.

You may get to know the concept ATDD (acceptance test driven development). TDD could be used in every phase of the development and by the different granularity.

To ATDD, you could consider on using some existing framework such as FIT, these frameworks will be bridge between business logic and implementation logic.

Recently, the concept BDD (behavior driven development) is introduced to the ATDD process, so the BDD frameworks such as JBehave is also the good choice.

 


Different TDD process could be nested and should be nested don’t let your step too large.

 

4 keep each step small enough

Always keep each step small to avoid introducing the untestable codes or logics and pass each test quickly.

 

 

6 Always refactor

This step is always overlooked in TDD process; however it is the very important step. Also, never forget refactor should involve all your tests.

 

Why can't write test firstly?

 1.not think how to meature the codes

2. The current step maybe too large, should separate into small ones

3. The codes with ugly dependencies

 

Chao Cai (蔡超)

Sr. SDE

Amazon.com

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值