<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    朱雀的IT世界

    每天進步一點點,努力做好自己

     

    同事的一篇Blog 講使用TDD 其實核心不在于測試,而在于測試的回饋:影響設計和后續的好處

    When asked "Do you write tests?", a lot of developers these days will say "of course" as their answers. However, not everyone can admit to doing TDD (Test Driven Development) correctly. Test Driven Development says, a developer will write a test that fails first, then write code to make the test pass, and refactor when possible, and repeat. This is what most people's TDD rhythm is. For the most part this is fairly easy to do. But to reach the next level, one has to understand TDD as a tool: TDD means more than just test your own code. Here is a couple tips on what the last "D" means:

    Discipline

    It takes a great deal of discipline to even write a failing test before writing the actual code. Sometimes, we write a little seudo-code here, or move a method definition there, or changing code else where trying to see if more new code needs to be written after it, and sooner than you think you are writing the actual implementation of the methods you wanted to test (Test Afterwards Development anyone?). Other times you write the test, but you are too anxious to even run it and see it fails. And other times you want to jump into the actual code immediately when you see your new test fails, but failing for the unexpected reasons.

    Don't fall into these traps. If anything is true, testing is hard, but it is at the same time rewarding and fun. What's also true is, it will pay off. Write the failing test, draw up your list of tests you will need to write, and satisfy them one by one. Having discipline is the cornerstone of becoming a better programmer.

    Design

    It takes too long to write a test? Tests are running too slowly? Are your tests difficult to read? Are they too brittle and fail all the time? Hang in there! You ever had the feeling you saw code in the codebase that irks the living hell out of your mind written by someone else on your team? Well, it is time for you to get some of these feedback about your own code. Yay, your code sucks! Your tests are telling you that! Let's address each of these one by one.

    Slow running tests? You shouldn't be hitting a database or web service in your unit tests, because you can mock/stub them out. Difficult to mock/stub it out? There probably is a better way to design your classes your tests are hitting. Ever heard of Inversion of Control (or Dependency Injection)? Master them. True TDD masters use them extensively.

    Unreadable tests? Is it because of too many mocks/stubs? Or is it the code is 500 lines long and doing high octane 720-double-backflip logic? Either way, you have to learn to like small objects. Check this blog post of mine out.

    Hard to test something? Tests too brittle? Perhaps you have encapsulation issues in your class design. If your classes are referencing 15 other neighbors, of course they are hard to mock/stub. Chances are, you have to spend time to debug your tests to find out what's wrong! Heard of Law of Demeter? Even if you have, take a look at this highly entertaining yet informative post. It might change your perspective a little.

    The bottom line is, TDD is a way to guide you to writing good code, but only if you know how to use it as a tool. Now that you know, hopefully you will have a new perspective next time you write a test.

    posted on 2007-12-06 11:48 朱雀 閱讀(279) 評論(1)  編輯  收藏

    評論

    # re: 同事的一篇Blog 講使用TDD 其實核心不在于測試,而在于測試的回饋:影響設計和后續的好處[未登錄] 2008-01-12 08:50 Michael Chen

    If we refer another post/article, we always leave the original link for the readers' reference.  回復  更多評論   


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(5)

    隨筆分類

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 精品无码一级毛片免费视频观看| 亚洲最大视频网站| 猫咪免费观看人成网站在线| 成人人观看的免费毛片| 亚洲一级黄色大片| 久久电影网午夜鲁丝片免费| 中文字幕亚洲精品无码| 在线成人a毛片免费播放| 亚洲国产精华液2020| 国产美女无遮挡免费视频网站 | 一级做a爰性色毛片免费| 亚洲男人天堂2020| 成人片黄网站色大片免费观看cn| 亚洲色大成网站WWW久久九九| 久久精品私人影院免费看| 亚洲日本一区二区| 美女视频黄a视频全免费| 亚洲日韩AV一区二区三区四区| 国产裸模视频免费区无码| 二级毛片免费观看全程| 亚洲成AV人片在线播放无码| 中文字幕视频免费| 亚洲熟妇AV日韩熟妇在线| 无码欧精品亚洲日韩一区夜夜嗨| EEUSS影院WWW在线观看免费| 亚洲∧v久久久无码精品| 亚洲国产日韩一区高清在线| 57PAO成人国产永久免费视频 | 亚洲一区二区三区电影| 噼里啪啦电影在线观看免费高清 | 日韩免费在线中文字幕| 亚洲精品无码久久一线| 青青草a免费线观a| 特级毛片A级毛片免费播放| 亚洲av无码一区二区三区乱子伦| 一区在线免费观看| 亚洲美女中文字幕| 亚洲?v女人的天堂在线观看| 一区二区三区四区免费视频| 国产偷国产偷亚洲清高APP| 亚洲韩国精品无码一区二区三区|