<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 朱雀 閱讀(280) 評論(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)

    隨筆分類

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲激情在线观看| 国产国拍精品亚洲AV片| 亚洲国产精品久久人人爱| 一级毛片免费视频| 亚洲欧洲日韩国产综合在线二区| a级男女仿爱免费视频| 亚洲av无码无在线观看红杏| 国产亚洲免费的视频看| 在线免费观看亚洲| 黄在线观看www免费看| 国产午夜亚洲精品| 免费国产成人高清视频网站| 高清免费久久午夜精品| 亚洲国产精品成人精品无码区| 久久国产精品免费看| 亚洲人成在线免费观看| 免费观看国产小粉嫩喷水| 一个人看的www在线免费视频| 久久精品国产亚洲AV果冻传媒| 99久久99久久免费精品小说| 亚洲人成图片网站| 亚洲国产中文字幕在线观看| 久久精品成人免费看| 亚洲伊人色一综合网| 国产乱子伦片免费观看中字| 你懂的在线免费观看| 亚洲国产精品乱码在线观看97| 国产男女猛烈无遮挡免费视频| 国产精品视频全国免费观看| 亚洲黄网站wwwwww| 免费国产一级特黄久久| 亚洲午夜免费视频| 久久亚洲中文字幕无码| 亚洲国产精品嫩草影院在线观看 | 在线精品免费视频无码的 | 日本一道本不卡免费 | 中文字幕天天躁日日躁狠狠躁免费| 最新国产成人亚洲精品影院| 亚洲精品视频在线看| 一个人免费观看视频www| jizz免费在线观看|