{"id":611,"date":"2017-09-25T04:43:35","date_gmt":"2017-09-25T04:43:35","guid":{"rendered":"http:\/\/lg.yusemo.com\/?p=611"},"modified":"2017-09-25T04:45:08","modified_gmt":"2017-09-25T04:45:08","slug":"%e7%bc%96%e5%86%99%e5%8d%95%e5%85%83%e6%b5%8b%e8%af%95%e7%9a%84%e4%b8%80%e4%ba%9b%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/lg.yusemo.com\/?p=611","title":{"rendered":"\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u7684\u4e00\u4e9b\u6280\u5de7"},"content":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttp:\/\/www.techug.com\/post\/19-unit-test-code-tips.html<\/p>\n<p>\u672c\u6587\u662f\u770b\u5230\u6709\u524d\u4eba\u7684\u603b\u7ed3\uff0c\u8f6c\u8f7d\u4ee5\u8bb0\u5f55\u6536\u85cf<\/p>\n<p><a href=\"https:\/\/promotion.aliyun.com\/ntms\/act\/ambassador\/sharetouser.html?userCode=6nvdkyj2&amp;utm_source=6nvdkyj2\">\u70b9\u6211\u9886\u53d6\u963f\u91cc\u4e91\u4f18\u60e0\u7801<\/a><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-585\" src=\"http:\/\/lg.yusemo.com\/wp-content\/uploads\/2016\/11\/\u5934\u50cf-1.jpg\" alt=\"\" width=\"268\" height=\"268\" srcset=\"https:\/\/lg.yusemo.com\/wp-content\/uploads\/2016\/11\/\u5934\u50cf-1.jpg 268w, https:\/\/lg.yusemo.com\/wp-content\/uploads\/2016\/11\/\u5934\u50cf-1-150x150.jpg 150w\" sizes=\"(max-width: 268px) 100vw, 268px\" \/><\/p>\n<p><strong>\u5982\u4f55\u7f16\u5199\u66f4\u597d\u7684\u5355\u5143\u6d4b\u8bd5<\/strong><\/p>\n<p>\u5355\u5143\u6d4b\u8bd5\u5728\u6700\u8fd1\u7684\u5de5\u4f5c\u4e2d\u4f7f\u7528\u6bd4\u8f83\u5e7f\u6cdb\uff0c\u6211\u5df2\u7ecf\u6536\u96c6\u4e86\u4e00\u4e9b\u5173\u4e8e\u5982\u4f55\u7f16\u5199\u66f4\u597d\u7684\u6d4b\u8bd5\u7c7b\u7684\u51c6\u5219\uff0c\u5e76\u4e14\u6211\u5df2\u7ecf\u5c1d\u8bd5\u7740\u575a\u6301\u8fd9\u4e9b\u51c6\u5219\u591a\u5e74\u4e86\u3002\u8bb0\u4f4f\uff0c\u7f16\u5199\u7cdf\u7cd5\u7684\u6d4b\u8bd5\u662f\u5728\u6d6a\u8d39\u65f6\u95f4\uff0c\u5e76\u4f1a\u5728\u4ee5\u540e\u9020\u6210\u66f4\u5927\u7684\u95ee\u9898\u3002\u6240\u4ee5\u6700\u597d\u628a\u8fd9\u4e9b\u51c6\u5219\u8bb0\u5728\u5fc3\u91cc\u3002<\/p>\n<ol>\n<li><strong>\u4e0d\u5e94\u8be5\u7f16\u5199\u6210\u529f\u901a\u8fc7\u7684\u5355\u5143\u6d4b\u8bd5<\/strong>-\u5b83\u4eec\u5e94\u8be5\u88ab\u5199\u6210\u4e0d\u901a\u8fc7\u7684\u3002\u4f60\u53ef\u4ee5\u5728\u51e0\u5206\u949f\u5185\u8ba9\u4efb\u4f55\u4e00\u7ec4\u6d4b\u8bd5\u901a\u8fc7\uff0c\u4f46\u8fd9\u53ea\u662f\u5728\u6b3a\u9a97\u4f60\u81ea\u5df1\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u7c7b\u5e94\u8be5\u53ea\u6d4b\u8bd5\u4e00\u4e2a\u529f\u80fd<\/strong>-\u4f60\u5e94\u8be5\u7528\u4e00\u4e2a\u529f\u80fd\u53bb\u6d4b\u8bd5\u4e00\u4e2a\u65b9\u6cd5\u3002\u5426\u5219\uff0c\u4f60\u4f1a\u8fdd\u53cd\u4e86<a href=\"https:\/\/www.jeremymorgan.com\/blog\/programming\/single-responsibility-principle\/\" target=\"_blank\" rel=\"nofollow noopener\">\u5355\u4e00\u804c\u8d23\u539f\u5219<\/a>\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u7c7b\u5177\u5907\u53ef\u8bfb\u6027<\/strong>-\u786e\u4fdd\u6d4b\u8bd5\u7c7b\u6807\u6709\u6ce8\u91ca\u5e76\u4e14\u5bb9\u6613\u7406\u89e3\uff0c\u5c31\u50cf\u5176\u4ed6\u7684\u4ee3\u7801\u4e00\u6837\u3002<\/li>\n<li><strong>\u826f\u597d\u7684\u547d\u540d\u89c4\u8303<\/strong>-\u518d\u6b21\u6d4b\u8bd5\u65f6\u5e94\u8be5\u50cf\u5176\u4ed6\u4ee3\u7801\u4e00\u6837-\u4fbf\u4e8e\u4eba\u4eec\u7406\u89e3\u3002<\/li>\n<li><strong>\u628a\u65ad\u8a00\u4ece\u884c\u4e3a\u4e2d\u5206\u79bb\u51fa\u6765<\/strong>-\u4f60\u7684\u65ad\u8a00\u5e94\u8be5\u7528\u6765\u68c0\u9a8c\u7ed3\u679c\uff0c\u800c\u4e0d\u662f\u6267\u884c\u903b\u8f91\u64cd\u4f5c\u7684\u3002<\/li>\n<li><strong>\u4f7f\u7528\u5177\u4f53\u7684\u8f93\u5165<\/strong>-\u4e0d\u8981\u4f7f\u7528\u4efb\u4f55\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6570\u636e\u6765\u8f93\u5165\uff0c\u50cfdate()\u8fd9\u4e9b\u4ea7\u751f\u7684\u6570\u636e\u4f1a\u5f15\u5165\u5dee\u5f02\u3002<\/li>\n<li><strong>\u628a\u6d4b\u8bd5\u7c7b\u5206\u7c7b\uff0c\u653e\u5728\u4e0d\u540c\u7684\u5730\u65b9<\/strong>-\u4ece\u903b\u8f91\u7684\u89d2\u5ea6\u770b\uff0c\u5f53\u6ca1\u6709\u9519\u8bef\u6307\u5411\u7279\u5b9a\u7684\u95ee\u9898\u65f6\u8fd9\u66f4\u5bb9\u6613\u53bb\u67e5\u627e\u3002<\/li>\n<li><strong>\u597d\u7684\u6d4b\u8bd5\u90fd\u662f\u4e00\u4e9b\u72ec\u7acb\u7684\u6d4b\u8bd5\u7c7b<\/strong>-\u4f60\u5e94\u8be5\u8ba9\u6d4b\u8bd5\u7c7b\u4e0e\u5176\u4ed6\u7684\u6d4b\u8bd5\u3001\u73af\u5883\u8bbe\u7f6e\u7b49\u6ca1\u6709\u4efb\u4f55\u4f9d\u8d56\u3002\u8fd9\u5229\u4e8e\u521b\u5efa\u591a\u4e2a\u6d4b\u8bd5\u70b9\u3002<\/li>\n<li><strong>\u4e0d\u8981\u5305\u542b\u79c1\u6709\u7684\u65b9\u6cd5<\/strong>-\u4ed6\u4eec\u90fd\u662f\u4e00\u4e9b\u5177\u4f53\u7684\u5b9e\u73b0\uff0c\u4e0d\u5e94\u8be5\u5305\u542b\u5728\u5355\u5143\u6d4b\u8bd5\u91cc\u3002<\/li>\n<li><strong>\u4e0d\u8981\u8fde\u63a5\u6570\u636e\u5e93\u6216\u8005\u6570\u636e\u6e90<\/strong>-\u8fd9\u662f\u4e0d\u9760\u8c31\u7684\u3002\u56e0\u4e3a\u4f60\u4e0d\u80fd\u786e\u4fdd\u6570\u636e\u670d\u52a1\u603b\u662f\u4e00\u6837\u7684\u5e76\u4e14\u80fd\u591f\u521b\u5efa\u6d4b\u8bd5\u70b9\u3002<\/li>\n<li><strong>\u4e00\u4e2a\u6d4b\u8bd5\u4e0d\u8981\u8d85\u8fc7\u4e00\u4e2a\u6a21\u62df(mock\u5bf9\u8c61)<\/strong>-\u6211\u4eec\u52aa\u529b\u53bb\u6d88\u9664\u9519\u8bef\u548c\u4e0d\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u5355\u5143\u6d4b\u8bd5\u4e0d\u662f\u96c6\u6210\u6d4b\u8bd5<\/strong>-\u5982\u679c\u4f60\u60f3\u6d4b\u8bd5\u7ed3\u679c\uff0c\u4e0d\u8981\u4f7f\u7528\u5355\u5143\u6d4b\u8bd5\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u5fc5\u987b\u5177\u6709\u786e\u5b9a\u6027<\/strong>-\u4f60\u9700\u8981\u4e00\u4e2a\u786e\u5b9a\u7684\u9884\u6d4b\u7ed3\u679c\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u6709\u65f6\u5019\u6d4b\u8bd5\u901a\u8fc7\u4e86\uff0c\u4f46\u662f\u4e0d\u610f\u5473\u7740\u5b8c\u6210\u6d4b\u8bd5\u4e86\u3002<\/li>\n<li><strong>\u4fdd\u6301\u4f60\u7684\u6d4b\u8bd5\u662f\u5e42\u7b49\u7684<\/strong>-\u4f60\u5e94\u8be5\u80fd\u591f\u8fd0\u884c\u4f60\u7684\u6d4b\u8bd5\u591a\u6b21\u800c\u4e0d\u6539\u53d8\u5b83\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u5e76\u4e14\u6d4b\u8bd5\u4e5f\u4e0d\u5e94\u8be5\u6539\u53d8\u4efb\u4f55\u7684\u6570\u636e\u6216\u8005\u6dfb\u52a0\u4efb\u4f55\u4e1c\u897f\u3002\u65e0\u8bba\u662f\u8fd0\u884c\u4e00\u6b21\u8fd8\u662f\u4e00\u767e\u4e07\u6b21\uff0c\u5b83\u7684\u6548\u679c\u90fd\u5e94\u8be5\u662f\u4e00\u6837\u7684\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u7c7b\u4e00\u6b21\u4ec5\u6d4b\u8bd5\u4e00\u4e2a\u7c7b\uff0c\u6d4b\u8bd5\u65b9\u6cd5\u4e00\u6b21\u4ec5\u6d4b\u8bd5\u4e00\u4e2a\u65b9\u6cd5-<\/strong>\u7ec4\u7ec7\u65b9\u6cd5\u80fd\u591f\u5728\u95ee\u9898\u51fa\u73b0\u65f6\u68c0\u6d4b\u51fa\u6765\uff0c\u5e76\u5e2e\u4f60\u786e\u5b9a\u6d4b\u8bd5\u4f9d\u8d56\u3002<\/li>\n<li><strong>\u5728\u4f60\u7684\u6d4b\u8bd5\u91cc\u4f7f\u7528\u5f02\u5e38<\/strong>-\u4f60\u5728\u6d4b\u8bd5\u91cc\u4f1a\u9047\u5230\u5f02\u5e38\uff0c\u6240\u4ee5\uff0c\u8bf7\u4e0d\u8981\u5ffd\u7565\u5b83\uff0c\u8981\u4f7f\u7528\u5b83\u3002<\/li>\n<li><strong>\u4e0d\u8981\u4f7f\u7528\u4f60\u81ea\u5df1\u7684\u6d4b\u8bd5\u7c7b\u53bb\u6d4b\u8bd5\u7b2c\u4e09\u65b9\u5e93\u7684\u529f\u80fd<\/strong>-\u5927\u591a\u6570\u597d\u7684\u5e93\u90fd\u5e94\u8be5\u6709\u5b83\u4eec\u81ea\u5df1\u7684\u6d4b\u8bd5\uff0c\u5982\u679c\u6ca1\u8003\u8651\u7528mocks\u53bb\u4ea7\u751f\u4e00\u81f4\u6027\u7684\u7ed3\u679c\u7684\u8bdd\u3002<\/li>\n<li><strong>\u9650\u5236\u89c4\u5219<\/strong>-\u5f53\u5728\u4e00\u4e9b\u89c4\u5219\u4e0b\u5199\u6d4b\u8bd5\u65f6\uff0c\u8bb0\u4f4f\u4f60\u7684\u9650\u5236\u548c\u5b83\u4eec\uff08\u6700\u5c0f\u548c\u6700\u5927\uff09\u8bbe\u7f6e\u6210\u6700\u5927\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u7c7b\u4e0d\u5e94\u8be5\u9700\u8981\u914d\u7f6e\u6216\u8005\u81ea\u5b9a\u4e49\u5b89\u88c5<\/strong>-\u4f60\u7684\u6d4b\u8bd5\u7c7b\u5e94\u8be5\u80fd\u591f\u7ed9\u4efb\u4f55\u4eba\u4f7f\u7528\u5e76\u4e14\u4f7f\u5b83\u8fd0\u884c\u3002\u201c\u5728\u6211\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u201d\u4e0d\u5e94\u8be5\u51fa\u73b0\u5728\u8fd9\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttp:\/\/www.techug.com\/post\/19-unit-test-code-tips.html \u672c\u6587\u662f\u770b\u5230\u6709\u524d\u4eba\u7684\u603b\u7ed3\uff0c\u8f6c\u8f7d\u4ee5\u8bb0\u5f55\u6536\u85cf \u70b9\u6211\u9886\u53d6\u963f\u91cc\u4e91\u4f18\u60e0\u7801 \u5982\u4f55\u7f16\u5199\u66f4\u597d\u7684\u5355\u5143\u6d4b\u8bd5 \u5355\u5143\u6d4b\u8bd5\u5728\u6700\u8fd1\u7684\u5de5\u4f5c\u4e2d\u4f7f\u7528\u6bd4\u8f83\u5e7f\u6cdb\uff0c\u6211\u5df2\u7ecf\u6536\u96c6\u4e86\u4e00\u4e9b\u5173\u4e8e\u5982\u4f55\u7f16\u5199\u66f4\u597d\u7684\u6d4b\u8bd5\u7c7b\u7684\u51c6\u5219\uff0c\u5e76\u4e14\u6211\u5df2\u7ecf\u5c1d\u8bd5&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,21],"tags":[38],"_links":{"self":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/611"}],"collection":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=611"}],"version-history":[{"count":3,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/611\/revisions"}],"predecessor-version":[{"id":614,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=\/wp\/v2\/posts\/611\/revisions\/614"}],"wp:attachment":[{"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lg.yusemo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}